ref: 298b974eacaa5d338401e7f06593ab72f518a30c
parent: 6f175d289e57bf447640255d484f411f631195be
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Feb 10 17:53:18 EST 2017
libsec: import from 9front
--- a/include/libsec.h
+++ b/include/libsec.h
@@ -357,8 +357,8 @@
PEMChain* decodepemchain(char *s, char *type);
uchar* X509rsagen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
uchar* X509rsareq(RSApriv *priv, char *subj, int *certlen);
-char* X509rsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, RSApub *pk);
char* X509rsaverify(uchar *cert, int ncert, RSApub *pk);
+char* X509rsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, RSApub *pk);
void X509dump(uchar *cert, int ncert);
@@ -528,9 +528,9 @@
int ecencodepub(ECdomain *dom, ECpub *, uchar *, int);
void ecpubfree(ECpub *);
-ECpub* X509toECpub(uchar *cert, int ncert, ECdomain *dom);
+ECpub* X509toECpub(uchar *cert, int ncert, char *name, int nname, ECdomain *dom);
+char* X509ecdsaverify(uchar *cert, int ncert, ECdomain *dom, ECpub *pub);
char* X509ecdsaverifydigest(uchar *sig, int siglen, uchar *edigest, int edigestlen, ECdomain *dom, ECpub *pub);
-char* X509ecdsaverify(uchar *sig, int siglen, ECdomain *dom, ECpub *pub);
/* curves */
void secp256r1(mpint *p, mpint *a, mpint *b, mpint *x, mpint *y, mpint *n, mpint *h);
--- a/libsec/x509.c
+++ b/libsec/x509.c
@@ -2314,17 +2314,26 @@
}
ECpub*
-X509toECpub(uchar *cert, int ncert, ECdomain *dom)
+X509toECpub(uchar *cert, int ncert, char *name, int nname, ECdomain *dom)
{
CertX509 *c;
ECpub *pub;
Bytes *b;
+ if(name != nil)
+ memset(name, 0, nname);
+
b = makebytes(cert, ncert);
c = decode_cert(b);
freebytes(b);
if(c == nil)
return nil;
+ if(name != nil && c->subject != nil){
+ char *e = strchr(c->subject, ',');
+ if(e != nil)
+ *e = 0; /* take just CN part of Distinguished Name */
+ strncpy(name, c->subject, nname);
+ }
pub = nil;
if(c->publickey_alg == ALG_ecPublicKey){
ecdominit(dom, namedcurves[c->curve]);
@@ -2365,7 +2374,6 @@
RSApub*
X509toRSApub(uchar *cert, int ncert, char *name, int nname)
{
- char *e;
Bytes *b;
CertX509 *c;
RSApub *pub;
@@ -2379,7 +2387,7 @@
if(c == nil)
return nil;
if(name != nil && c->subject != nil){
- e = strchr(c->subject, ',');
+ char *e = strchr(c->subject, ',');
if(e != nil)
*e = 0; /* take just CN part of Distinguished Name */
strncpy(name, c->subject, nname);