3 changed files with 131 additions and 54 deletions
@ -0,0 +1,29 @@ |
|||
from posix import Tm, mktime |
|||
import |
|||
openssl, |
|||
openssl_additional, |
|||
times |
|||
|
|||
type |
|||
Certificate* = string |
|||
|
|||
proc getPublicKey*(cert: Certificate): string = |
|||
let x509 = d2i_X509(cert) |
|||
let pubKey = X509_get0_pubkey_bitstr(x509) |
|||
let pubKeyLen = ASN1_STRING_length(pubKey) |
|||
result = newString(pubKeyLen) |
|||
copyMem(addr result[0], ASN1_STRING_get0_data(pubKey), pubKeyLen) |
|||
X509_free(x509) |
|||
|
|||
proc getValidityPeriod*(cert: Certificate): tuple[notBefore: Time, notAfter: Time] = |
|||
let x509 = d2i_X509(cert) |
|||
let notBeforeAsn1 = X509_get0_notBefore(x509) |
|||
let notAfterAsn1 = X509_get0_notAfter(x509) |
|||
var notBeforeTm, notAfterTm: Tm |
|||
discard ASN1_TIME_to_tm(notBeforeAsn1, addr notBeforeTm) |
|||
discard ASN1_TIME_to_tm(notAfterAsn1, addr notAfterTm) |
|||
let notBeforeUnix = cast[int64](mktime(notBeforeTm)) |
|||
let notAfterUnix = cast[int64](mktime(notAfterTm)) |
|||
result = (fromUnix(notBeforeUnix), fromUnix(notAfterUnix)) |
|||
X509_free(x509) |
|||
|
@ -0,0 +1,57 @@ |
|||
import openssl |
|||
from posix import Tm |
|||
|
|||
const |
|||
X509_V_FLAG_CHECK_SS_SIGNATURE* = 0x00004000 |
|||
|
|||
type |
|||
PASN1_STRING* = SslPtr |
|||
PASN1_BIT_STRING* = PASN1_STRING |
|||
PASN1_TIME* = PASN1_STRING |
|||
PASN1_INTEGER* = PASN1_STRING |
|||
PX509_STORE_CTX* = SslPtr |
|||
PX509_VERIFY_PARAM* = SslPtr |
|||
|
|||
proc X509_free*(a: PX509) {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_get0_pubkey_bitstr*(x: PX509): PASN1_BIT_STRING {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_get0_notBefore*(x: PX509): PASN1_TIME {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_get0_notAfter*(x: PX509): PASN1_TIME {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc ASN1_STRING_length*(x: PASN1_STRING): int {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc ASN1_STRING_get0_data*(x: PASN1_STRING): ptr cuchar {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc ASN1_TIME_to_tm*(s: PASN1_TIME, tm: ptr Tm): int {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_verify_cert*(ctx: PX509_STORE_CTX): int {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_get0_untrusted*(ctx: PX509_STORE_CTX): PSTACK {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_get0_store*(ctx: PX509_STORE_CTX): PX509_STORE {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_get0_param*(ctx: PX509_STORE_CTX): PX509_VERIFY_PARAM {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_VERIFY_PARAM_get_flags*(param: PX509_VERIFY_PARAM): culong {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_VERIFY_PARAM_set_flags*(param: PX509_VERIFY_PARAM, |
|||
flags: culong): int {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc PEM_read_PrivateKey*(fp: File, x: ptr EVP_PKEY, |
|||
cb: proc(buf: cstring, size: cint, rwflag: cint, u: pointer): cint {.cdecl.}, |
|||
u: pointer): EVP_PKEY |
|||
{.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc EVP_PKEY_free*(key: EVP_PKEY) {.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_new*(): PX509_STORE_CTX |
|||
{.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_free*(ctx: PX509_STORE_CTX) |
|||
{.importc, dynlib: DLLSSLName, cdecl.} |
|||
|
|||
proc X509_STORE_CTX_init*(ctx: PX509_STORE_CTX, store: PX509_STORE, x509: PX509, |
|||
chain: PSTACK): cint |
|||
{.importc, dynlib: DLLSSLName, cdecl.} |
Loading…
Reference in new issue