📄 slp_auth.c
字号:
{ result = SLP_ERROR_AUTHENTICATION_FAILED; } else { result = SLP_ERROR_OK; } /*-----------------*/ /* Get a timestamp */ /*-----------------*/ timestamp = time(NULL); /*------------------------------------------------------*/ /* Iterate and check all authentication blocks */ /*------------------------------------------------------*/ /* If any one of the authblocks can be verified then we */ /* accept it */ for(i=0;i<authcount;i++) { /*-------------------------------*/ /* Get a public key for the SPI */ /*-------------------------------*/ key = SLPSpiGetDSAKey(hspi, SLPSPI_KEY_TYPE_PUBLIC, autharray[i].spistrlen, autharray[i].spistr, &key); /* Continue if we have a key and if the authenticator is not */ /* timed out */ if(key && timestamp <= autharray[i].timestamp) { /*------------------------------------------------------------*/ /* Calculate the size of the DSA signature from the authblock */ /*------------------------------------------------------------*/ /* we have to calculate the signature length since */ /* autharray[i].length is (stupidly) the length of the entire */ /* authblock */ signaturelen = autharray[i].length - (autharray[i].spistrlen + 10); /*----------------------*/ /* Verify the signature */ /*----------------------*/ if(SLPCryptoDSAVerify(key, digest, SLPAUTH_SHA1_DIGEST_SIZE, autharray[i].authstruct, signaturelen)) { break; } result = SLP_ERROR_AUTHENTICATION_FAILED; } } return result;}/*=========================================================================*/int SLPAuthVerifyString(SLPSpiHandle hspi, int emptyisfail, unsigned short stringlen, const char* string, int authcount, const SLPAuthBlock* autharray)/* Verify authenticity of the specified attribute list *//* *//* Parameters: hspi (IN) open SPI handle *//* emptyisfail (IN) if non-zero, messages without authblocks *//* will fail *//* stringlen (IN) the length of string to verify *//* string (IN) the list to verify *//* authcount (IN) the number of blocks in autharray *//* autharray (IN) array of authblocks *//* *//* Returns: 0 on success or SLP_ERROR_xxx code on failure *//*=========================================================================*/{ int i; int signaturelen; int result; unsigned long timestamp; SLPCryptoDSAKey* key = 0; unsigned char digest[SLPAUTH_SHA1_DIGEST_SIZE]; /*-----------------------------------*/ /* Should we fail on emtpy authblock */ /*-----------------------------------*/ if(emptyisfail) { result = SLP_ERROR_AUTHENTICATION_FAILED; } else { result = SLP_ERROR_OK; } /*-----------------*/ /* Get a timestamp */ /*-----------------*/ timestamp = time(NULL); /*------------------------------------------------------*/ /* Iterate and check all authentication blocks */ /*------------------------------------------------------*/ /* If any one of the authblocks can be verified then we */ /* accept it */ for(i=0;i<authcount;i++) { /*-------------------------------*/ /* Get a public key for the SPI */ /*-------------------------------*/ key = SLPSpiGetDSAKey(hspi, SLPSPI_KEY_TYPE_PUBLIC, autharray[i].spistrlen, autharray[i].spistr, &key); /* Continue if we have a key and if the authenticator is not */ /* timed out */ if(key && timestamp <= autharray[i].timestamp) { /*--------------------------*/ /* Generate the SHA1 digest */ /*--------------------------*/ result = SLPAuthDigestString(autharray[i].spistrlen, autharray[i].spistr, stringlen, string, autharray[i].timestamp, digest); if(result == 0) { /*------------------------------------------------------------*/ /* Calculate the size of the DSA signature from the authblock */ /*------------------------------------------------------------*/ /* we have to calculate the signature length since */ /* autharray[i].length is (stupidly) the length of the entire */ /* authblock */ signaturelen = autharray[i].length - (autharray[i].spistrlen + 10); /*----------------------*/ /* Verify the signature */ /*----------------------*/ if(SLPCryptoDSAVerify(key, digest, sizeof(digest), autharray[i].authstruct, signaturelen)) { break; } result = SLP_ERROR_AUTHENTICATION_FAILED; } } } if(key) SLPCryptoDSAKeyDestroy(key); return result;}/*=========================================================================*/int SLPAuthVerifyUrl(SLPSpiHandle hspi, int emptyisfail, const SLPUrlEntry* urlentry)/* Verify authenticity of the specified url entry *//* *//* Parameters: hspi (IN) open SPI handle *//* emptyisfail (IN) if non-zero, messages without authblocks *//* will fail *//* urlentry (IN) the url entry to verify *//* *//* Returns: 0 on success or SLP_ERROR_xxx code on failure *//*=========================================================================*/{ return SLPAuthVerifyString(hspi, emptyisfail, urlentry->urllen, urlentry->url, urlentry->authcount, urlentry->autharray);}/*=========================================================================*/int SLPAuthVerifyDAAdvert(SLPSpiHandle hspi, int emptyisfail, const SLPDAAdvert* daadvert)/* Verify authenticity of the specified DAAdvert *//* *//* Parameters: hspi (IN) open SPI handle *//* (IN) if non-zero, messages without authblocks *//* will fail *//* spistrlen (IN) length of the spi string *//* sprstr (IN) the spi string *//* daadvert (IN) the DAAdvert to verify *//* *//* Returns: 0 on success or SLP_ERROR_xxx code on failure *//*=========================================================================*/{ int i; int signaturelen; int result; unsigned long timestamp; const SLPAuthBlock* autharray; int authcount; SLPCryptoDSAKey* key = 0; unsigned char digest[SLPAUTH_SHA1_DIGEST_SIZE]; /*-----------------------------------*/ /* Should we fail on emtpy authblock */ /*-----------------------------------*/ if(emptyisfail) { result = SLP_ERROR_AUTHENTICATION_FAILED; } else { result = SLP_ERROR_OK; } /*-----------------*/ /* Get a timestamp */ /*-----------------*/ timestamp = time(NULL); /*------------------------------------------------------*/ /* Iterate and check all authentication blocks */ /*------------------------------------------------------*/ /* If any one of the authblocks can be verified then we */ /* accept it */ authcount = daadvert->authcount; autharray = daadvert->autharray; for(i=0;i<authcount;i++) { /*-------------------------------*/ /* Get a public key for the SPI */ /*-------------------------------*/ key = SLPSpiGetDSAKey(hspi, SLPSPI_KEY_TYPE_PUBLIC, autharray[i].spistrlen, autharray[i].spistr, &key); /* Continue if we have a key and if the authenticator is not */ /* timed out */ if(key && timestamp <= autharray[i].timestamp) { /*--------------------------*/ /* Generate the SHA1 digest */ /*--------------------------*/ result = SLPAuthDigestDAAdvert(autharray[i].spistrlen, autharray[i].spistr, autharray[i].timestamp, daadvert->bootstamp, daadvert->urllen, daadvert->url, daadvert->attrlistlen, daadvert->attrlist, daadvert->scopelistlen, daadvert->scopelist, daadvert->spilistlen, daadvert->spilist, digest); if(result == 0) { /*------------------------------------------------------------*/ /* Calculate the size of the DSA signature from the authblock */ /*------------------------------------------------------------*/ /* we have to calculate the signature length since */ /* autharray[i].length is (stupidly) the length of the entire */ /* authblock */ signaturelen = autharray[i].length - (autharray[i].spistrlen + 10); /*----------------------*/ /* Verify the signature */ /*----------------------*/ if(SLPCryptoDSAVerify(key, digest, sizeof(digest), autharray[i].authstruct, signaturelen)) { break; } result = SLP_ERROR_AUTHENTICATION_FAILED; } } } if(key) SLPCryptoDSAKeyDestroy(key); return result;}/*=========================================================================*/int SLPAuthVerifySAAdvert(SLPSpiHandle hspi, int emptyisfail,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -