mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-06-23 05:33:39 +08:00
Update Tools
This commit is contained in:
@@ -50,11 +50,12 @@
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/x509_crl.h>
|
||||
|
||||
|
||||
static const char *options = "[-in file] [-out file]";
|
||||
static const char *options = "-in file [-out file]";
|
||||
|
||||
int crlparse_main(int argc, char **argv)
|
||||
{
|
||||
@@ -64,12 +65,21 @@ int crlparse_main(int argc, char **argv)
|
||||
char *outfile = NULL;
|
||||
FILE *infp = stdin;
|
||||
FILE *outfp = stdout;
|
||||
uint8_t crl[64 * 1024];
|
||||
struct stat st;
|
||||
uint8_t *in = NULL;
|
||||
size_t inlen;
|
||||
const uint8_t *pin;
|
||||
const uint8_t *crl = NULL;
|
||||
size_t crllen;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
if (argc < 1) {
|
||||
fprintf(stderr, "usage: %s %s\n", prog, options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (argc > 0) {
|
||||
if (!strcmp(*argv, "-help")) {
|
||||
printf("usage: %s %s\n", prog, options);
|
||||
@@ -100,23 +110,37 @@ bad:
|
||||
argv++;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int rv;
|
||||
|
||||
if ((rv = x509_crl_from_fp(crl, &crllen, sizeof(crl), infp)) != 1) {
|
||||
if (rv < 0) fprintf(stderr, "%s: read CRL failure\n", prog);
|
||||
else ret = 0;
|
||||
goto end;
|
||||
}
|
||||
x509_crl_print(outfp, 0, 0, "CRL", crl, crllen);
|
||||
if (x509_crl_to_pem(crl, crllen, outfp) != 1) {
|
||||
fprintf(stderr, "%s: output CRL failure\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (!infile) {
|
||||
fprintf(stderr, "%s: '-in' option required\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (fstat(fileno(infp), &st) < 0) {
|
||||
fprintf(stderr, "%s: access file error : %s\n", prog, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
if ((inlen = st.st_size) <= 0) {
|
||||
fprintf(stderr, "%s: invalid input length\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (!(in = malloc(inlen))) {
|
||||
fprintf(stderr, "%s: malloc failure\n", prog);
|
||||
goto end;
|
||||
}
|
||||
if (fread(in, 1, inlen, infp) != inlen) {
|
||||
fprintf(stderr, "%s: read file error : %s\n", prog, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
pin = in;
|
||||
if (x509_crl_from_der(&crl, &crllen, &pin, &inlen) != 1
|
||||
|| asn1_length_is_zero(inlen) != 1) {
|
||||
fprintf(stderr, "%s: read CRL failure\n", prog);
|
||||
goto end;
|
||||
}
|
||||
x509_crl_print(outfp, 0, 0, "CRL", crl, crllen);
|
||||
|
||||
end:
|
||||
if (infile && infp) fclose(infp);
|
||||
if (outfile && outfp) fclose(outfp);
|
||||
if (in) free(in);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user