changed tab spacing from 8 to 4

This commit is contained in:
Andreas Steffen 2007-04-10 19:31:42 +00:00
parent 00ccb87671
commit 241ab32c10
2 changed files with 432 additions and 441 deletions

View File

@ -55,56 +55,51 @@ static u_char ASN1_noRevAvail_ext_str[] = {
static const chunk_t ASN1_noRevAvail_ext = strchunk(ASN1_noRevAvail_ext_str); static const chunk_t ASN1_noRevAvail_ext = strchunk(ASN1_noRevAvail_ext_str);
/* /**
* build directoryName * build directoryName
*/ */
static chunk_t static chunk_t build_directoryName(asn1_t tag, chunk_t name)
build_directoryName(asn1_t tag, chunk_t name)
{ {
return asn1_wrap(tag, "m" return asn1_wrap(tag, "m",
, asn1_simple_object(ASN1_CONTEXT_C_4, name)); asn1_simple_object(ASN1_CONTEXT_C_4, name));
} }
/* /**
* build holder * build holder
*/ */
static chunk_t static chunk_t build_holder(void)
build_holder(void)
{ {
return asn1_wrap(ASN1_SEQUENCE, "mm" return asn1_wrap(ASN1_SEQUENCE, "mm",
, asn1_wrap(ASN1_CONTEXT_C_0, "mm" asn1_wrap(ASN1_CONTEXT_C_0, "mm",
, build_directoryName(ASN1_SEQUENCE, user->issuer) build_directoryName(ASN1_SEQUENCE, user->issuer),
, asn1_simple_object(ASN1_INTEGER, user->serialNumber) asn1_simple_object(ASN1_INTEGER, user->serialNumber)
) ),
, build_directoryName(ASN1_CONTEXT_C_1, user->subject)); build_directoryName(ASN1_CONTEXT_C_1, user->subject));
} }
/* /**
* build v2Form * build v2Form
*/ */
static chunk_t static chunk_t build_v2_form(void)
build_v2_form(void)
{ {
return asn1_wrap(ASN1_CONTEXT_C_0, "m" return asn1_wrap(ASN1_CONTEXT_C_0, "m",
, build_directoryName(ASN1_SEQUENCE, signer->subject)); build_directoryName(ASN1_SEQUENCE, signer->subject));
} }
/* /**
* build attrCertValidityPeriod * build attrCertValidityPeriod
*/ */
static chunk_t static chunk_t build_attr_cert_validity(void)
build_attr_cert_validity(void)
{ {
return asn1_wrap(ASN1_SEQUENCE, "mm" return asn1_wrap(ASN1_SEQUENCE, "mm",
, timetoasn1(&notBefore, ASN1_GENERALIZEDTIME) timetoasn1(&notBefore, ASN1_GENERALIZEDTIME),
, timetoasn1(&notAfter, ASN1_GENERALIZEDTIME)); timetoasn1(&notAfter, ASN1_GENERALIZEDTIME));
} }
/* /**
* build attributes * build attributes
*/ */
static chunk_t static chunk_t build_ietfAttributes(ietfAttrList_t *list)
build_ietfAttributes(ietfAttrList_t *list)
{ {
chunk_t ietfAttributes; chunk_t ietfAttributes;
ietfAttrList_t *item = list; ietfAttrList_t *item = list;
@ -146,97 +141,91 @@ build_ietfAttributes(ietfAttrList_t *list)
return asn1_wrap(ASN1_SEQUENCE, "m", ietfAttributes); return asn1_wrap(ASN1_SEQUENCE, "m", ietfAttributes);
} }
/* /**
* build attribute type * build attribute type
*/ */
static chunk_t static chunk_t build_attribute_type(const chunk_t type, chunk_t content)
build_attribute_type(const chunk_t type, chunk_t content)
{ {
return asn1_wrap(ASN1_SEQUENCE, "cm" return asn1_wrap(ASN1_SEQUENCE, "cm",
, type type,
, asn1_wrap(ASN1_SET, "m", content)); asn1_wrap(ASN1_SET, "m", content));
} }
/* /**
* build attributes * build attributes
*/ */
static chunk_t static chunk_t build_attributes(void)
build_attributes(void)
{ {
return asn1_wrap(ASN1_SEQUENCE, "m" return asn1_wrap(ASN1_SEQUENCE, "m",
, build_attribute_type(ASN1_group_oid build_attribute_type(ASN1_group_oid,
, build_ietfAttributes(groups))); build_ietfAttributes(groups)));
} }
/* /**
* build authorityKeyIdentifier * build authorityKeyIdentifier
*/ */
static chunk_t static chunk_t build_authorityKeyID(x509cert_t *signer)
build_authorityKeyID(x509cert_t *signer)
{ {
chunk_t keyIdentifier = (signer->subjectKeyID.ptr == NULL) chunk_t keyIdentifier = (signer->subjectKeyID.ptr == NULL)
? empty_chunk ? empty_chunk
: asn1_simple_object(ASN1_CONTEXT_S_0 : asn1_simple_object(ASN1_CONTEXT_S_0,
, signer->subjectKeyID); signer->subjectKeyID);
chunk_t authorityCertIssuer = build_directoryName(ASN1_CONTEXT_C_1 chunk_t authorityCertIssuer = build_directoryName(ASN1_CONTEXT_C_1,
, signer->issuer); signer->issuer);
chunk_t authorityCertSerialNumber = asn1_simple_object(ASN1_CONTEXT_S_2 chunk_t authorityCertSerialNumber = asn1_simple_object(ASN1_CONTEXT_S_2,
, signer->serialNumber); signer->serialNumber);
return asn1_wrap(ASN1_SEQUENCE, "cm" return asn1_wrap(ASN1_SEQUENCE, "cm",
, ASN1_authorityKeyIdentifier_oid ASN1_authorityKeyIdentifier_oid,
, asn1_wrap(ASN1_OCTET_STRING, "m" asn1_wrap(ASN1_OCTET_STRING, "m",
, asn1_wrap(ASN1_SEQUENCE, "mmm" asn1_wrap(ASN1_SEQUENCE, "mmm",
, keyIdentifier keyIdentifier,
, authorityCertIssuer authorityCertIssuer,
, authorityCertSerialNumber authorityCertSerialNumber
) )
) )
); );
} }
/* /**
* build extensions * build extensions
*/ */
static chunk_t static chunk_t build_extensions(void)
build_extensions(void)
{ {
return asn1_wrap(ASN1_SEQUENCE, "mc" return asn1_wrap(ASN1_SEQUENCE, "mc",
, build_authorityKeyID(signer) build_authorityKeyID(signer),
, ASN1_noRevAvail_ext); ASN1_noRevAvail_ext);
} }
/* /**
* build attributeCertificateInfo * build attributeCertificateInfo
*/ */
static chunk_t static chunk_t build_attr_cert_info(void)
build_attr_cert_info(void)
{ {
return asn1_wrap(ASN1_SEQUENCE, "cmmcmmmm" return asn1_wrap(ASN1_SEQUENCE, "cmmcmmmm",
, ASN1_INTEGER_1 ASN1_INTEGER_1,
, build_holder() build_holder(),
, build_v2_form() build_v2_form(),
, ASN1_sha1WithRSA_id ASN1_sha1WithRSA_id,
, asn1_simple_object(ASN1_INTEGER, serial) asn1_simple_object(ASN1_INTEGER, serial),
, build_attr_cert_validity() build_attr_cert_validity(),
, build_attributes() build_attributes(),
, build_extensions()); build_extensions());
} }
/* /**
* build an X.509 attribute certificate * build an X.509 attribute certificate
*/ */
chunk_t chunk_t build_attr_cert(void)
build_attr_cert(void)
{ {
chunk_t attributeCertificateInfo = build_attr_cert_info(); chunk_t attributeCertificateInfo = build_attr_cert_info();
chunk_t signatureValue = pkcs1_build_signature(attributeCertificateInfo chunk_t signatureValue = pkcs1_build_signature(attributeCertificateInfo,
, OID_SHA1, signerkey, TRUE); OID_SHA1, signerkey, TRUE);
return asn1_wrap(ASN1_SEQUENCE, "mcm" return asn1_wrap(ASN1_SEQUENCE, "mcm",
, attributeCertificateInfo attributeCertificateInfo,
, ASN1_sha1WithRSA_id ASN1_sha1WithRSA_id,
, signatureValue); signatureValue);
} }

View File

@ -58,9 +58,10 @@ static void
usage(const char *mess) usage(const char *mess)
{ {
if (mess != NULL && *mess != '\0') if (mess != NULL && *mess != '\0')
{
fprintf(stderr, "%s\n", mess); fprintf(stderr, "%s\n", mess);
fprintf(stderr }
, "Usage: openac" fprintf(stderr, "Usage: openac"
" [--help]" " [--help]"
" [--version]" " [--version]"
" [--optionsfrom <filename>]" " [--optionsfrom <filename>]"
@ -91,11 +92,10 @@ usage(const char *mess)
exit(mess == NULL? 0 : 1); exit(mess == NULL? 0 : 1);
} }
/* /**
* read the last serial number from file * read the last serial number from file
*/ */
static chunk_t static chunk_t read_serial(void)
read_serial(void)
{ {
MP_INT number; MP_INT number;
@ -115,16 +115,21 @@ read_serial(void)
err_t ugh = ttodata(buf, 0, 16, bytes, BUF_LEN, &len); err_t ugh = ttodata(buf, 0, 16, bytes, BUF_LEN, &len);
if (ugh != NULL) if (ugh != NULL)
{
plog(" error reading serial number from %s: %s" plog(" error reading serial number from %s: %s"
, OPENAC_SERIAL, ugh); , OPENAC_SERIAL, ugh);
} }
}
fclose(fd); fclose(fd);
} }
else else
{
plog(" file '%s' does not exist yet - serial number set to 01" plog(" file '%s' does not exist yet - serial number set to 01"
, OPENAC_SERIAL); , OPENAC_SERIAL);
}
/* conversion of read serial number to a multiprecision integer /**
* conversion of read serial number to a multiprecision integer
* and incrementing it by one * and incrementing it by one
* and representing it as a two's complement octet string * and representing it as a two's complement octet string
*/ */
@ -136,11 +141,10 @@ read_serial(void)
return serial; return serial;
} }
/* /**
* write back the last serial number to file * write back the last serial number to file
*/ */
static void static void write_serial(chunk_t serial)
write_serial(chunk_t serial)
{ {
char buf[BUF_LEN]; char buf[BUF_LEN];
@ -154,10 +158,12 @@ write_serial(chunk_t serial)
fclose(fd); fclose(fd);
} }
else else
{
plog(" could not open file '%s' for writing", OPENAC_SERIAL); plog(" could not open file '%s' for writing", OPENAC_SERIAL);
}
} }
/* /**
* global variables accessible by both main() and build.c * global variables accessible by both main() and build.c
*/ */
x509cert_t *user = NULL; x509cert_t *user = NULL;
@ -171,9 +177,7 @@ time_t notAfter = 0;
chunk_t serial; chunk_t serial;
int main(int argc, char **argv)
int
main(int argc, char **argv)
{ {
char *keyfile = NULL; char *keyfile = NULL;
char *certfile = NULL; char *certfile = NULL;
@ -296,8 +300,7 @@ main(int argc, char **argv)
char *endptr; char *endptr;
long days = strtol(optarg, &endptr, 0); long days = strtol(optarg, &endptr, 0);
if (*endptr != '\0' || endptr == optarg if (*endptr != '\0' || endptr == optarg || days <= 0)
|| days <= 0)
usage("<days> must be a positive number"); usage("<days> must be a positive number");
validity += 24*3600*days; validity += 24*3600*days;
} }
@ -310,8 +313,7 @@ main(int argc, char **argv)
char *endptr; char *endptr;
long hours = strtol(optarg, &endptr, 0); long hours = strtol(optarg, &endptr, 0);
if (*endptr != '\0' || endptr == optarg if (*endptr != '\0' || endptr == optarg || hours <= 0)
|| hours <= 0)
usage("<hours> must be a positive number"); usage("<hours> must be a positive number");
validity += 3600*hours; validity += 3600*hours;
} }
@ -337,7 +339,7 @@ main(int argc, char **argv)
case 'o': /* --outt */ case 'o': /* --outt */
outfile = optarg; outfile = optarg;
continue ; continue;
#ifdef DEBUG #ifdef DEBUG
case 'A': /* --debug-all */ case 'A': /* --debug-all */