changed tab spacing from 8 to 4
This commit is contained in:
+72
-83
@@ -55,56 +55,51 @@ static u_char ASN1_noRevAvail_ext_str[] = {
|
||||
|
||||
static const chunk_t ASN1_noRevAvail_ext = strchunk(ASN1_noRevAvail_ext_str);
|
||||
|
||||
/*
|
||||
/**
|
||||
* build directoryName
|
||||
*/
|
||||
static chunk_t
|
||||
build_directoryName(asn1_t tag, chunk_t name)
|
||||
static chunk_t build_directoryName(asn1_t tag, chunk_t name)
|
||||
{
|
||||
return asn1_wrap(tag, "m"
|
||||
, asn1_simple_object(ASN1_CONTEXT_C_4, name));
|
||||
return asn1_wrap(tag, "m",
|
||||
asn1_simple_object(ASN1_CONTEXT_C_4, name));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build holder
|
||||
*/
|
||||
static chunk_t
|
||||
build_holder(void)
|
||||
static chunk_t build_holder(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mm"
|
||||
, asn1_wrap(ASN1_CONTEXT_C_0, "mm"
|
||||
, build_directoryName(ASN1_SEQUENCE, user->issuer)
|
||||
, asn1_simple_object(ASN1_INTEGER, user->serialNumber)
|
||||
)
|
||||
, build_directoryName(ASN1_CONTEXT_C_1, user->subject));
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mm",
|
||||
asn1_wrap(ASN1_CONTEXT_C_0, "mm",
|
||||
build_directoryName(ASN1_SEQUENCE, user->issuer),
|
||||
asn1_simple_object(ASN1_INTEGER, user->serialNumber)
|
||||
),
|
||||
build_directoryName(ASN1_CONTEXT_C_1, user->subject));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build v2Form
|
||||
*/
|
||||
static chunk_t
|
||||
build_v2_form(void)
|
||||
static chunk_t build_v2_form(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_CONTEXT_C_0, "m"
|
||||
, build_directoryName(ASN1_SEQUENCE, signer->subject));
|
||||
return asn1_wrap(ASN1_CONTEXT_C_0, "m",
|
||||
build_directoryName(ASN1_SEQUENCE, signer->subject));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build attrCertValidityPeriod
|
||||
*/
|
||||
static chunk_t
|
||||
build_attr_cert_validity(void)
|
||||
static chunk_t build_attr_cert_validity(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mm"
|
||||
, timetoasn1(¬Before, ASN1_GENERALIZEDTIME)
|
||||
, timetoasn1(¬After, ASN1_GENERALIZEDTIME));
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mm",
|
||||
timetoasn1(¬Before, ASN1_GENERALIZEDTIME),
|
||||
timetoasn1(¬After, ASN1_GENERALIZEDTIME));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build attributes
|
||||
*/
|
||||
static chunk_t
|
||||
build_ietfAttributes(ietfAttrList_t *list)
|
||||
static chunk_t build_ietfAttributes(ietfAttrList_t *list)
|
||||
{
|
||||
chunk_t ietfAttributes;
|
||||
ietfAttrList_t *item = list;
|
||||
@@ -146,97 +141,91 @@ build_ietfAttributes(ietfAttrList_t *list)
|
||||
return asn1_wrap(ASN1_SEQUENCE, "m", ietfAttributes);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build attribute type
|
||||
*/
|
||||
static chunk_t
|
||||
build_attribute_type(const chunk_t type, chunk_t content)
|
||||
static chunk_t build_attribute_type(const chunk_t type, chunk_t content)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cm"
|
||||
, type
|
||||
, asn1_wrap(ASN1_SET, "m", content));
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cm",
|
||||
type,
|
||||
asn1_wrap(ASN1_SET, "m", content));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build attributes
|
||||
*/
|
||||
static chunk_t
|
||||
build_attributes(void)
|
||||
static chunk_t build_attributes(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "m"
|
||||
, build_attribute_type(ASN1_group_oid
|
||||
, build_ietfAttributes(groups)));
|
||||
return asn1_wrap(ASN1_SEQUENCE, "m",
|
||||
build_attribute_type(ASN1_group_oid,
|
||||
build_ietfAttributes(groups)));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build authorityKeyIdentifier
|
||||
*/
|
||||
static chunk_t
|
||||
build_authorityKeyID(x509cert_t *signer)
|
||||
static chunk_t build_authorityKeyID(x509cert_t *signer)
|
||||
{
|
||||
chunk_t keyIdentifier = (signer->subjectKeyID.ptr == NULL)
|
||||
? empty_chunk
|
||||
: asn1_simple_object(ASN1_CONTEXT_S_0
|
||||
, signer->subjectKeyID);
|
||||
: asn1_simple_object(ASN1_CONTEXT_S_0,
|
||||
signer->subjectKeyID);
|
||||
|
||||
chunk_t authorityCertIssuer = build_directoryName(ASN1_CONTEXT_C_1
|
||||
, signer->issuer);
|
||||
chunk_t authorityCertIssuer = build_directoryName(ASN1_CONTEXT_C_1,
|
||||
signer->issuer);
|
||||
|
||||
chunk_t authorityCertSerialNumber = asn1_simple_object(ASN1_CONTEXT_S_2
|
||||
, signer->serialNumber);
|
||||
chunk_t authorityCertSerialNumber = asn1_simple_object(ASN1_CONTEXT_S_2,
|
||||
signer->serialNumber);
|
||||
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cm"
|
||||
, ASN1_authorityKeyIdentifier_oid
|
||||
, asn1_wrap(ASN1_OCTET_STRING, "m"
|
||||
, asn1_wrap(ASN1_SEQUENCE, "mmm"
|
||||
, keyIdentifier
|
||||
, authorityCertIssuer
|
||||
, authorityCertSerialNumber
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cm",
|
||||
ASN1_authorityKeyIdentifier_oid,
|
||||
asn1_wrap(ASN1_OCTET_STRING, "m",
|
||||
asn1_wrap(ASN1_SEQUENCE, "mmm",
|
||||
keyIdentifier,
|
||||
authorityCertIssuer,
|
||||
authorityCertSerialNumber
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build extensions
|
||||
*/
|
||||
static chunk_t
|
||||
build_extensions(void)
|
||||
static chunk_t build_extensions(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mc"
|
||||
, build_authorityKeyID(signer)
|
||||
, ASN1_noRevAvail_ext);
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mc",
|
||||
build_authorityKeyID(signer),
|
||||
ASN1_noRevAvail_ext);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build attributeCertificateInfo
|
||||
*/
|
||||
static chunk_t
|
||||
build_attr_cert_info(void)
|
||||
static chunk_t build_attr_cert_info(void)
|
||||
{
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cmmcmmmm"
|
||||
, ASN1_INTEGER_1
|
||||
, build_holder()
|
||||
, build_v2_form()
|
||||
, ASN1_sha1WithRSA_id
|
||||
, asn1_simple_object(ASN1_INTEGER, serial)
|
||||
, build_attr_cert_validity()
|
||||
, build_attributes()
|
||||
, build_extensions());
|
||||
return asn1_wrap(ASN1_SEQUENCE, "cmmcmmmm",
|
||||
ASN1_INTEGER_1,
|
||||
build_holder(),
|
||||
build_v2_form(),
|
||||
ASN1_sha1WithRSA_id,
|
||||
asn1_simple_object(ASN1_INTEGER, serial),
|
||||
build_attr_cert_validity(),
|
||||
build_attributes(),
|
||||
build_extensions());
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* build an X.509 attribute certificate
|
||||
*/
|
||||
chunk_t
|
||||
build_attr_cert(void)
|
||||
chunk_t build_attr_cert(void)
|
||||
{
|
||||
chunk_t attributeCertificateInfo = build_attr_cert_info();
|
||||
chunk_t signatureValue = pkcs1_build_signature(attributeCertificateInfo
|
||||
, OID_SHA1, signerkey, TRUE);
|
||||
chunk_t signatureValue = pkcs1_build_signature(attributeCertificateInfo,
|
||||
OID_SHA1, signerkey, TRUE);
|
||||
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mcm"
|
||||
, attributeCertificateInfo
|
||||
, ASN1_sha1WithRSA_id
|
||||
, signatureValue);
|
||||
return asn1_wrap(ASN1_SEQUENCE, "mcm",
|
||||
attributeCertificateInfo,
|
||||
ASN1_sha1WithRSA_id,
|
||||
signatureValue);
|
||||
}
|
||||
|
||||
+20
-18
@@ -58,9 +58,10 @@ static void
|
||||
usage(const char *mess)
|
||||
{
|
||||
if (mess != NULL && *mess != '\0')
|
||||
{
|
||||
fprintf(stderr, "%s\n", mess);
|
||||
fprintf(stderr
|
||||
, "Usage: openac"
|
||||
}
|
||||
fprintf(stderr, "Usage: openac"
|
||||
" [--help]"
|
||||
" [--version]"
|
||||
" [--optionsfrom <filename>]"
|
||||
@@ -91,11 +92,10 @@ usage(const char *mess)
|
||||
exit(mess == NULL? 0 : 1);
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* read the last serial number from file
|
||||
*/
|
||||
static chunk_t
|
||||
read_serial(void)
|
||||
static chunk_t read_serial(void)
|
||||
{
|
||||
MP_INT number;
|
||||
|
||||
@@ -115,16 +115,21 @@ read_serial(void)
|
||||
err_t ugh = ttodata(buf, 0, 16, bytes, BUF_LEN, &len);
|
||||
|
||||
if (ugh != NULL)
|
||||
{
|
||||
plog(" error reading serial number from %s: %s"
|
||||
, OPENAC_SERIAL, ugh);
|
||||
}
|
||||
}
|
||||
fclose(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
plog(" file '%s' does not exist yet - serial number set to 01"
|
||||
, 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 representing it as a two's complement octet string
|
||||
*/
|
||||
@@ -136,11 +141,10 @@ read_serial(void)
|
||||
return serial;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* write back the last serial number to file
|
||||
*/
|
||||
static void
|
||||
write_serial(chunk_t serial)
|
||||
static void write_serial(chunk_t serial)
|
||||
{
|
||||
char buf[BUF_LEN];
|
||||
|
||||
@@ -154,10 +158,12 @@ write_serial(chunk_t serial)
|
||||
fclose(fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
plog(" could not open file '%s' for writing", OPENAC_SERIAL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* global variables accessible by both main() and build.c
|
||||
*/
|
||||
x509cert_t *user = NULL;
|
||||
@@ -171,9 +177,7 @@ time_t notAfter = 0;
|
||||
|
||||
chunk_t serial;
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *keyfile = NULL;
|
||||
char *certfile = NULL;
|
||||
@@ -296,8 +300,7 @@ main(int argc, char **argv)
|
||||
char *endptr;
|
||||
long days = strtol(optarg, &endptr, 0);
|
||||
|
||||
if (*endptr != '\0' || endptr == optarg
|
||||
|| days <= 0)
|
||||
if (*endptr != '\0' || endptr == optarg || days <= 0)
|
||||
usage("<days> must be a positive number");
|
||||
validity += 24*3600*days;
|
||||
}
|
||||
@@ -310,8 +313,7 @@ main(int argc, char **argv)
|
||||
char *endptr;
|
||||
long hours = strtol(optarg, &endptr, 0);
|
||||
|
||||
if (*endptr != '\0' || endptr == optarg
|
||||
|| hours <= 0)
|
||||
if (*endptr != '\0' || endptr == optarg || hours <= 0)
|
||||
usage("<hours> must be a positive number");
|
||||
validity += 3600*hours;
|
||||
}
|
||||
@@ -337,7 +339,7 @@ main(int argc, char **argv)
|
||||
|
||||
case 'o': /* --outt */
|
||||
outfile = optarg;
|
||||
continue ;
|
||||
continue;
|
||||
|
||||
#ifdef DEBUG
|
||||
case 'A': /* --debug-all */
|
||||
|
||||
Reference in New Issue
Block a user