use of com.google.showcase.v1beta1.Sequence in project libSBOLj by SynBioDex.
the class SequenceOutput method main.
public static void main(String[] args) throws Exception {
String prURI = "http://partsregistry.org/";
SBOLDocument document = new SBOLDocument();
document.setDefaultURIprefix(prURI);
document.setTypesInURIs(true);
Sequence seq = document.createSequence("BBa_J23119", "", "ttgacagctagctcagtcctaggtataatgctagc", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
seq.addWasDerivedFrom(URI.create("http://parts.igem.org/Part:BBa_J23119:Design"));
SBOLWriter.write(document, (System.out));
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class CRLDistributionPoint method main.
public static void main(String[] args) throws GeneralNamesException, IOException, InvalidBERException {
try (FileOutputStream fos = new FileOutputStream(args[0]);
ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
if (args.length != 1) {
System.out.println("Usage: CRLDistributionPoint <outfile>");
System.exit(-1);
}
SEQUENCE cdps = new SEQUENCE();
// URI only
CRLDistributionPoint cdp = new CRLDistributionPoint();
URIName uri = new URIName("http://www.mycrl.com/go/here");
GeneralNames generalNames = new GeneralNames();
generalNames.addElement(uri);
cdp.setFullName(generalNames);
cdps.addElement(cdp);
// DN only
cdp = new CRLDistributionPoint();
X500Name dn = new X500Name("CN=Otis Smith,E=otis@fedoraproject.org" + ",OU=Certificate Server,O=Fedora,C=US");
generalNames = new GeneralNames();
generalNames.addElement(dn);
cdp.setFullName(generalNames);
cdps.addElement(cdp);
// DN + reason
BitArray ba = new BitArray(5, new byte[] { (byte) 0x28 });
cdp = new CRLDistributionPoint();
cdp.setFullName(generalNames);
cdp.setReasons(ba);
cdps.addElement(cdp);
// relative DN + reason + crlIssuer
cdp = new CRLDistributionPoint();
RDN rdn = new RDN("OU=foobar dept");
cdp.setRelativeName(rdn);
cdp.setReasons(ba);
cdp.setCRLIssuer(generalNames);
cdps.addElement(cdp);
cdps.encode(bos);
byte[] encoded = bos.toByteArray();
fos.write(encoded);
SEQUENCE.OF_Template seqt = new SEQUENCE.OF_Template(getTemplate());
cdps = (SEQUENCE) ASN1Util.decode(seqt, encoded);
int size = cdps.size();
System.out.println("Total number of CDPs: " + size);
for (int i = 0; i < size; i++) {
System.out.println("\nCDP " + i);
cdp = (CRLDistributionPoint) cdps.elementAt(i);
GeneralNames gn = cdp.getFullName();
if (gn == null) {
System.out.println("No full name");
} else {
System.out.println(gn);
}
rdn = cdp.getRelativeName();
if (rdn == null) {
System.out.println("No relative name");
} else {
System.out.println(rdn);
}
if (cdp.getReasons() == null) {
System.out.println("No reasons");
} else {
System.out.println(cdp.getReasons());
}
gn = cdp.getCRLIssuer();
if (gn == null) {
System.out.println("No cRLIssuer");
} else {
System.out.println(gn);
}
}
System.out.println("Done");
}
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class CRLDistributionPoint method encode.
@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
SEQUENCE seq = new SEQUENCE();
DerOutputStream derOut;
try {
// is a CHOICE, the [0] tag is forced to be EXPLICIT.
if (fullName != null) {
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), fullNameEncoding);
seq.addElement(distPoint);
} else if (relativeName != null) {
derOut = new DerOutputStream();
relativeName.encode(derOut);
ANY rn = new ANY(derOut.toByteArray());
EXPLICIT raw = new EXPLICIT(Tag.get(1), rn);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encode(bos);
ANY distPointName = new ANY(bos.toByteArray());
EXPLICIT distPoint = new EXPLICIT(Tag.get(0), distPointName);
seq.addElement(distPoint);
}
// Encodes the ReasonFlags.
if (reasons != null) {
derOut = new DerOutputStream();
derOut.putUnalignedBitString(reasons);
ANY raw = new ANY(derOut.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
raw.encodeWithAlternateTag(Tag.get(1), bos);
ANY reasonEncoding = new ANY(bos.toByteArray());
seq.addElement(Tag.get(1), reasonEncoding);
}
// Encodes the CRLIssuer
if (CRLIssuer != null) {
seq.addElement(Tag.get(2), CRLIssuerEncoding);
}
seq.encode(implicitTag, ostream);
} catch (InvalidBERException e) {
// the Sun encoding classes
throw new IOException(e.toString());
}
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class PKCS12Util method getCertInfos.
public void getCertInfos(PKCS12 pkcs12, PFX pfx, Password password) throws Exception {
logger.debug("Loading certificates:");
AuthenticatedSafes safes = pfx.getAuthSafes();
for (int i = 0; i < safes.getSize(); i++) {
SEQUENCE contents = safes.getSafeContentsAt(password, i);
for (int j = 0; j < contents.size(); j++) {
SafeBag bag = (SafeBag) contents.elementAt(j);
OBJECT_IDENTIFIER oid = bag.getBagType();
if (!oid.equals(SafeBag.CERT_BAG))
continue;
logger.debug(" - Certificate:");
PKCS12CertInfo certInfo = getCertInfo(bag);
pkcs12.addCertInfo(certInfo, true);
}
}
}
use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.
the class PKCS12Util method generatePFX.
public PFX generatePFX(PKCS12 pkcs12, Password password) throws Exception {
logger.info("Generating PKCS #12 data");
AuthenticatedSafes authSafes = new AuthenticatedSafes();
Collection<PKCS12KeyInfo> keyInfos = pkcs12.getKeyInfos();
Collection<PKCS12CertInfo> certInfos = pkcs12.getCertInfos();
if (!keyInfos.isEmpty()) {
SEQUENCE keySafeContents = new SEQUENCE();
for (PKCS12KeyInfo keyInfo : keyInfos) {
addKeyBag(keyInfo, password, keySafeContents);
}
authSafes.addSafeContents(keySafeContents);
}
if (!certInfos.isEmpty()) {
SEQUENCE certSafeContents = new SEQUENCE();
for (PKCS12CertInfo certInfo : certInfos) {
addCertBag(certInfo, certSafeContents);
}
if (certEncryption == null) {
authSafes.addSafeContents(certSafeContents);
} else if (certEncryption == PBEAlgorithm.PBE_SHA1_RC2_40_CBC) {
byte[] salt = new byte[16];
random.nextBytes(salt);
authSafes.addEncryptedSafeContents(certEncryption, password, salt, // iterations
100000, certSafeContents);
} else {
throw new Exception("Unsupported certificate encryption: " + certEncryption);
}
}
PFX pfx = new PFX(authSafes);
// Use the same salt size and number of iterations as in pk12util.
byte[] salt = new byte[16];
random.nextBytes(salt);
pfx.computeMacData(password, salt, 100000);
return pfx;
}
Aggregations