Oops, forgot message length

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3608 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-08-14 21:28:30 +00:00
parent 3ff53cd50b
commit 6723ea3afb
2 changed files with 8 additions and 8 deletions

View File

@@ -62,7 +62,7 @@ extern int ast_check_signature(struct ast_key *key, char *msg, char *sig);
* Returns 0 if the signature is valid, or -1 otherwise * Returns 0 if the signature is valid, or -1 otherwise
* *
*/ */
extern int ast_check_signature_bin(struct ast_key *key, char *msg, unsigned char *sig); extern int ast_check_signature_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig);
/*! /*!
* \param key a private key to use to create the signature * \param key a private key to use to create the signature
@@ -83,7 +83,7 @@ extern int ast_sign(struct ast_key *key, char *msg, char *sig);
* Returns 0 on success or -1 on failure. * Returns 0 on success or -1 on failure.
* *
*/ */
extern int ast_sign_bin(struct ast_key *key, char *msg, unsigned char *sig); extern int ast_sign_bin(struct ast_key *key, char *msg, int msglen, unsigned char *sig);
#if defined(__cplusplus) || defined(c_plusplus) #if defined(__cplusplus) || defined(c_plusplus)
} }

View File

@@ -296,7 +296,7 @@ static char *binary(int y, int len)
#endif #endif
int ast_sign_bin(struct ast_key *key, char *msg, unsigned char *dsig) int ast_sign_bin(struct ast_key *key, char *msg, int msglen, unsigned char *dsig)
{ {
unsigned char digest[20]; unsigned char digest[20];
int siglen = sizeof(dsig); int siglen = sizeof(dsig);
@@ -308,7 +308,7 @@ int ast_sign_bin(struct ast_key *key, char *msg, unsigned char *dsig)
} }
/* Calculate digest of message */ /* Calculate digest of message */
SHA1((unsigned char *)msg, strlen(msg), digest); SHA1((unsigned char *)msg, msglen, digest);
/* Verify signature */ /* Verify signature */
res = RSA_sign(NID_sha1, digest, sizeof(digest), dsig, &siglen, key->rsa); res = RSA_sign(NID_sha1, digest, sizeof(digest), dsig, &siglen, key->rsa);
@@ -332,7 +332,7 @@ int ast_sign(struct ast_key *key, char *msg, char *sig)
unsigned char dsig[128]; unsigned char dsig[128];
int siglen = sizeof(dsig); int siglen = sizeof(dsig);
int res; int res;
res = ast_sign_bin(key, msg, dsig); res = ast_sign_bin(key, msg, strlen(msg), dsig);
if (!res) if (!res)
/* Success -- encode (256 bytes max as documented) */ /* Success -- encode (256 bytes max as documented) */
ast_base64encode(sig, dsig, siglen, 256); ast_base64encode(sig, dsig, siglen, 256);
@@ -340,7 +340,7 @@ int ast_sign(struct ast_key *key, char *msg, char *sig)
} }
int ast_check_signature_bin(struct ast_key *key, char *msg, unsigned char *dsig) int ast_check_signature_bin(struct ast_key *key, char *msg, int msglen, unsigned char *dsig)
{ {
unsigned char digest[20]; unsigned char digest[20];
int res; int res;
@@ -353,7 +353,7 @@ int ast_check_signature_bin(struct ast_key *key, char *msg, unsigned char *dsig)
} }
/* Calculate digest of message */ /* Calculate digest of message */
SHA1((unsigned char *)msg, strlen(msg), digest); SHA1((unsigned char *)msg, msglen, digest);
/* Verify signature */ /* Verify signature */
res = RSA_verify(NID_sha1, digest, sizeof(digest), dsig, sizeof(dsig), key->rsa); res = RSA_verify(NID_sha1, digest, sizeof(digest), dsig, sizeof(dsig), key->rsa);
@@ -377,7 +377,7 @@ int ast_check_signature(struct ast_key *key, char *msg, char *sig)
ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res); ast_log(LOG_WARNING, "Signature improper length (expect %d, got %d)\n", (int)sizeof(dsig), (int)res);
return -1; return -1;
} }
res = ast_check_signature_bin(key, msg, dsig); res = ast_check_signature_bin(key, msg, strlen(msg), dsig);
return res; return res;
} }