Changeset e105d3e in mod_gnutls for test/gen_ocsp_index.c


Ignore:
Timestamp:
Jan 23, 2017, 11:15:16 PM (2 years ago)
Author:
Daniel Kahn Gillmor <dkg@…>
Branches:
debian/master, debian/stretch-backports, upstream
Children:
b824a91, f5342b1
Parents:
c598e21 (diff), 0202d6b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

New upstream version 0.8.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/gen_ocsp_index.c

    rc598e21 re105d3e  
    1919 * permissions and limitations under the License.
    2020 */
     21#include <stdint.h>
    2122#include <stdio.h>
    2223#include <stdlib.h>
     
    5152     * any */
    5253    char* revocation = "";
    53     /* serial number (hex) */
    54     char serial[128];
     54    /* serial number (hex), allocated when the length is known */
     55    char* serial = NULL;
    5556    /* certificate filename, or "unknown" */
    5657    char* fname = "unknown";
     
    6465    strftime(expires, sizeof(expires), "%y%m%d%H%M%SZ", &etmp);
    6566
    66     unsigned long long sno = 0;
    67     size_t serial_size = sizeof(sno);
    68     gnutls_x509_crt_get_serial(cert, &sno, &serial_size);
    69     snprintf(serial, sizeof(serial), "%llx", sno);
     67    /* determine size of the serial number (in bytes) */
     68    size_t serial_size = 0;
     69    gnutls_x509_crt_get_serial(cert, NULL, &serial_size);
     70    /* allocate memory for serial number and its string representation */
     71    uint8_t* sno = calloc(serial_size, sizeof(uint8_t));
     72    serial = calloc(serial_size * 2 + 1, sizeof(char));
     73    /* actually get the serial */
     74    gnutls_x509_crt_get_serial(cert, sno, &serial_size);
     75    /* print serial into the buffer byte for byte */
     76    for (int i = 0; i < serial_size; i++)
     77        snprintf(serial + (2 * i), 3, "%.2X", sno[i]);
     78    /* free binary serial */
     79    free(sno);
    7080
    7181    size_t dn_size = sizeof(dn);
     
    7484    fprintf(stdout, "%s\t%s\t%s\t%s\t%s\t%s\n",
    7585            flag, expires, revocation, serial, fname, dn);
     86
     87    /* free hex serial */
     88    free(serial);
    7689
    7790cleanup:
Note: See TracChangeset for help on using the changeset viewer.