... | ... |
@@ -632,21 +632,28 @@ static int pv_validity(sip_msg_t* msg, pv_param_t* param, pv_value_t* res) |
632 | 632 |
|
633 | 633 |
static int get_sn(str* res, int* ires, int local, sip_msg_t* msg) |
634 | 634 |
{ |
635 |
- static char buf[INT2STR_MAX_LEN]; |
|
635 |
+ static char buf[80]; // handle 256-bits log(2^256,10) |
|
636 | 636 |
X509* cert; |
637 | 637 |
struct tcp_connection* c; |
638 | 638 |
char* sn; |
639 |
- int num; |
|
639 |
+ BIGNUM* bn; |
|
640 | 640 |
|
641 | 641 |
if (get_cert(&cert, &c, msg, local) < 0) return -1; |
642 | 642 |
|
643 |
- num = ASN1_INTEGER_get(X509_get_serialNumber(cert)); |
|
644 |
- sn = int2str(num, &res->len); |
|
643 |
+ bn = BN_new(); |
|
644 |
+ ASN1_INTEGER_to_BN(X509_get_serialNumber(cert), bn); |
|
645 |
+ sn = BN_bn2dec(bn); |
|
646 |
+ res->len = strlen(sn); |
|
645 | 647 |
memcpy(buf, sn, res->len); |
646 | 648 |
res->s = buf; |
647 |
- if (ires) *ires = num; |
|
649 |
+ |
|
650 |
+ // cannot store serial number in int size var |
|
651 |
+ // if (ires) *ires = num; |
|
648 | 652 |
if (!local) X509_free(cert); |
649 | 653 |
tcpconn_put(c); |
654 |
+ |
|
655 |
+ BN_free(bn); |
|
656 |
+ OPENSSL_free(sn); |
|
650 | 657 |
return 0; |
651 | 658 |
} |
652 | 659 |
|
... | ... |
@@ -678,12 +685,13 @@ static int pv_sn(sip_msg_t* msg, pv_param_t* param, pv_value_t* res) |
678 | 685 |
BUG("could not determine certificate\n"); |
679 | 686 |
return pv_get_null(msg, param, res); |
680 | 687 |
} |
681 |
- |
|
682 |
- if (get_sn(&res->rs, &res->ri, local, msg) < 0) { |
|
688 |
+ |
|
689 |
+ // serial no can be > 2^64 cannot store in res->ri |
|
690 |
+ if (get_sn(&res->rs, NULL, local, msg) < 0) { |
|
683 | 691 |
return pv_get_null(msg, param, res); |
684 | 692 |
} |
685 | 693 |
|
686 |
- res->flags = PV_VAL_STR | PV_VAL_INT; |
|
694 |
+ res->flags = PV_VAL_STR; |
|
687 | 695 |
return 0; |
688 | 696 |
} |
689 | 697 |
|