30 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
52 m_pSKI = (ASN1_OCTET_STRING*) X509_get_ext_d2i(
m_pCert, NID_subject_key_identifier, NULL, NULL);
53 m_pAKI = (AUTHORITY_KEYID*) X509_get_ext_d2i (
m_pCert, NID_authority_key_identifier, NULL, NULL);
67 ASN1_OCTET_STRING* skid = NULL;
69 skid = ASN1_OCTET_STRING_new();
70 if(NULL == skid)
goto end;
72 ASN1_OCTET_STRING_set(skid, a_value, a_valueLen);
73 if( X509_add1_ext_i2d(
m_pCert, NID_subject_key_identifier, skid,
false, X509V3_ADD_REPLACE) == 1)
87 const DOMNode* node=n;
93 if(
equals(node->getNodeName(),
"X509PKCS12"))
117 node=node->getNextSibling();
123 if(
equals(node->getNodeName(),
"X509Certificate"))
147 node=node->getNextSibling();
159 EVP_PKEY* tmpKey=NULL;
161 const UINT8* tmp=buff;
166 #if OPENSSL_VERSION_NUMBER > 0x009070CfL
167 tmpCert=d2i_X509(NULL,&tmp,bufflen);
169 tmpCert=d2i_X509(NULL,(
UINT8**)&tmp,bufflen);
174 #if OPENSSL_VERSION_NUMBER > 0x009070CfL
175 tmpPKCS12=d2i_PKCS12(NULL,&tmp,bufflen);
177 tmpPKCS12=d2i_PKCS12(NULL,(
UINT8**)&tmp,bufflen);
181 ret=PKCS12_parse(tmpPKCS12,passwd,&tmpKey,&tmpCert,NULL);
182 PKCS12_free(tmpPKCS12);
183 EVP_PKEY_free(tmpKey);
195 DOMElement* root=doc->getDocumentElement();
196 if(root==NULL||!
equals(root->getNodeName(),
"X509Certificate"))
201 UINT32 tmpBuffSize=bufflen;
209 #if OPENSSL_VERSION_NUMBER > 0x009070CfL
210 tmpCert=d2i_X509(NULL,&tmp,tmpBuffSize);
212 tmpCert=d2i_X509(NULL,(
UINT8**)&tmp,tmpBuffSize);
228 if(
m_pCert==NULL||buff==NULL||bufflen==NULL)
241 #define X509_CERTIFICATE_TAGNAME_LEN 17
285 CAMsg::printMsg( LOG_ERR,
"Unable to get SKI from Certificate, trying to recover\n");
290 CAMsg::printMsg( LOG_ERR,
"Unable to retrieve 1SKI from Certificate\n");
308 CAMsg::printMsg( LOG_ERR,
"getSubjectKeyIdentifier: SKI is %s\n", cSki);
310 removeColons(cSki, strlen((
const char*)cSki), r_ski, r_skiLen);
324 UINT8 sha_hash[SHA_DIGEST_LENGTH];
325 X509_pubkey_digest(
m_pCert, EVP_sha1(), sha_hash, &
len);
344 UINT32 tmp = (2*a_cSkidLen)/3 + 2;
347 CAMsg::printMsg( LOG_ERR,
"CACertificate::removeColons: Unable to copy SKI to target array, size must at least be %i but is only %i!\n", tmp, *r_skiLen);
350 for(i = 0; i < a_cSkidLen; i++)
356 r_ski[i-j] = a_cSkid[i];
372 CAMsg::printMsg(LOG_ERR,
"Verification Error: Certificate is not valid!\n");
376 if(X509_NAME_cmp(X509_get_issuer_name(
m_pCert), X509_get_subject_name(a_cert->
m_pCert)) != 0)
384 if(ASN1_OCTET_STRING_cmp(
m_pAKI->keyid, a_cert->
m_pSKI) != 0)
386 CAMsg::printMsg(LOG_ERR,
"Verification Error: Key Identifiers do not match!\n");
391 EVP_PKEY* pubKey = X509_get_pubkey(a_cert->
m_pCert);
416 CAMsg::printMsg(LOG_ERR,
"Verification Error: Signature is not correct!\n");
422 #ifdef __BUILD_AS_SHADOW_PLUGIN__
428 #if OPENSSL_VERSION_NUMBER > 0x100020cfL
429 const ASN1_TIME* pValidNotBefore=X509_get0_notBefore(
m_pCert);
430 const ASN1_TIME* pValidNotAfter=X509_get0_notAfter(
m_pCert);
432 ASN1_TIME* pValidNotBefore=X509_get_notBefore(
m_pCert);
433 ASN1_TIME* pValidNotAfter=X509_get_notAfter(
m_pCert);
435 if(X509_cmp_current_time( pValidNotBefore) <0 && X509_cmp_current_time(pValidNotAfter) >0)
440 time_t now = time(NULL);
442 time = gmtime_r(&now, time);
445 time->tm_mon = time->tm_mon+10;
446 time->tm_year = time->tm_year-1;
450 time->tm_mon = time->tm_mon-2;
452 time_t ttiq = mktime(time);
455 if(X509_cmp_time( pValidNotBefore, &ttiq) <0 && X509_cmp_time(pValidNotAfter, &ttiq) >0)
457 CAMsg::printMsg(LOG_WARNING,
"Certificate is only valid within grace period of two months!\n");
470 CAMsg::printMsg( LOG_ERR,
"Unable to retrieve raw SKI from Certificate\n");
477 CAMsg::printMsg( LOG_ERR,
"Unable to copy SKI to target array, size must at least be %i but is only %i!\n",
m_pSKI->length, r_skiLen );
480 *r_skiLen =
m_pSKI->length;
483 r_ski[i] =
m_pSKI->data[i];
495 ASN1_OCTET_STRING* pKeyID = NULL;
503 UINT8* cKeyID = (
UINT8*)i2s_ASN1_OCTET_STRING(NULL, pKeyID);
508 removeColons(cKeyID, strlen((
const char*)cKeyID), r_aki, r_akiLen);
509 OPENSSL_free(cKeyID);
#define X509_CERTIFICATE_TAGNAME_LEN
#define CERT_X509CERTIFICATE
#define CERT_XML_X509CERTIFICATE
SINT32 getDOMElementValue(const DOMNode *const pElem, UINT8 *value, UINT32 *valuelen)
Returns the content of the text node(s) under elem as null-terminated C String.
SINT32 setDOMElementValue(DOMElement *pElem, SINT32 value)
bool equals(const XMLCh *const e1, const char *const e2)
XERCES_CPP_NAMESPACE::DOMDocument * parseDOMDocument(const UINT8 *const buff, UINT32 len)
Parses a buffer containing an XML document and returns this document.
DOMElement * createDOMElement(XERCES_CPP_NAMESPACE::DOMDocument *pOwnerDoc, const char *const name)
Creates a new DOMElement with the given name which belongs to the DOMDocument owernDoc.
static SINT32 encode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
static SINT32 decode(const UINT8 *in, UINT32 len, UINT8 *out, UINT32 *outlen)
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff...
SINT32 encode(UINT8 *buff, UINT32 *bufflen, UINT32 type) const
static UINT8 * m_spXmlElementName
SINT32 getAuthorityKeyIdentifier(UINT8 *r_aki, UINT32 *r_akiLen) const
SINT32 setSubjectKeyIdentifier()
LERNGRUPPE Sets the subjectKeyIdentifier extension for this certificate to the hash of the public key...
SINT32 verify(const CACertificate *a_cert) const
SINT32 getSubjectKeyIdentifier(UINT8 *r_ski, UINT32 *r_skiLen)
LERNGRUPPE Accessor method for the subjectKeyIdentifier (SKI) extension stored in this certificate.
static SINT32 removeColons(const UINT8 *a_cSki, UINT32 a_cSkiLen, UINT8 *&r_ski, UINT32 *r_skiLen)
LERNGRUPPE Removes the colons from the string representation of the given SKI.
SINT32 getRawSubjectKeyIdentifier(UINT8 *r_ski, UINT32 *r_skiLen)
static CACertificate * decode(const UINT8 *const buff, UINT32 bufflen, UINT32 type, const char *const passwd=NULL)
Extracts a certificate from an encoded (DER,XML) form.
ASN1_OCTET_STRING * m_pSKI
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.