367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
-
+
|
* A Tcl List Object representing the provided
* X509 certificate.
*
*------------------------------------------------------*
*/
Tcl_Obj*
Tls_NewX509Obj(Tcl_Interp *interp, X509 *cert) {
Tls_NewX509Obj(Tcl_Interp *interp, X509 *cert, int all) {
Tcl_Obj *certPtr = Tcl_NewListObj(0, NULL);
BIO *bio = BIO_new(BIO_s_mem());
int mdnid, pknid, bits, len;
unsigned int ulen;
uint32_t xflags;
char buffer[BUFSIZ];
unsigned char md[EVP_MAX_MD_SIZE];
|
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
|
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
|
+
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
-
+
+
+
+
+
|
unsigned char *string = X509_alias_get0(cert, &len);
LAPPEND_STR(interp, certPtr, "alias", (char *) string, (Tcl_Size) len);
string = X509_keyid_get0(cert, &len);
LAPPEND_STR(interp, certPtr, "keyId", (char *) string, (Tcl_Size) len);
}
/* Certificate and dump all data */
if (all) {
Tcl_Obj *allObj = Tcl_NewByteArrayObj(NULL, 0);
Tcl_Obj *certObj = Tcl_NewByteArrayObj(NULL, 0);
unsigned char *allStr, *certStr;
{
char certStr[CERT_STR_SIZE];
if (allObj == NULL || certObj == NULL) {
Tcl_DecrRefCount(allObj);
BIO_free(bio);
return certPtr;
}
/* Get certificate */
certStr = Tcl_SetByteArrayLength(certObj, CERT_STR_SIZE);
len = BIO_to_Buffer(PEM_write_bio_X509(bio, cert), bio, certStr, CERT_STR_SIZE);
Tcl_SetByteArrayLength(certObj, len);
LAPPEND_STR(interp, certPtr, "certificate", certStr, (Tcl_Size) len);
LAPPEND_OBJ(interp, certPtr, "certificate", certObj)
/* Get all cert info */
len = BIO_to_Buffer(X509_print_ex(bio, cert, flags, 0), bio, certStr, CERT_STR_SIZE);
LAPPEND_STR(interp, certPtr, "all", certStr, (Tcl_Size) len);
/* Get all info on certificate */
allStr = Tcl_SetByteArrayLength(allObj, CERT_STR_SIZE * 2);
len = BIO_to_Buffer(X509_print_ex(bio, cert, flags, 0), bio, allStr, CERT_STR_SIZE * 2);
Tcl_SetByteArrayLength(allObj, len);
LAPPEND_OBJ(interp, certPtr, "all", allObj)
}
BIO_free(bio);
return certPtr;
}
|