use of com.github.zhenwei.core.asn1.x509.Attribute in project ca3sCore by kuehne-trustable-de.
the class CaInternalConnector method signCertificateRequest.
public Certificate signCertificateRequest(CSR csr, CAConnectorConfig caConfig) throws GeneralSecurityException {
try {
csrUtil.setCsrAttribute(csr, CsrAttribute.ATTRIBUTE_CA_PROCESSING_STARTED_TIMESTAMP, "" + System.currentTimeMillis(), false);
csr.setStatus(CsrStatus.PROCESSING);
Certificate intermediate = getIntermediate();
PrivateKey privKeyIntermediate = certUtil.getPrivateKey(intermediate);
KeyPair kpIntermediate = new KeyPair(certUtil.convertPemToCertificate(intermediate.getContent()).getPublicKey(), privKeyIntermediate);
PKCS10CertificationRequest p10 = cryptoUtil.convertPemToPKCS10CertificationRequest(csr.getCsrBase64());
GeneralNames gns = null;
org.bouncycastle.asn1.pkcs.Attribute[] certAttributes = p10.getAttributes();
for (org.bouncycastle.asn1.pkcs.Attribute attribute : certAttributes) {
if (attribute.getAttrType().equals(PKCSObjectIdentifiers.pkcs_9_at_extensionRequest)) {
Extensions extensions = Extensions.getInstance(attribute.getAttrValues().getObjectAt(0));
gns = GeneralNames.fromExtensions(extensions, Extension.subjectAlternativeName);
}
}
X509Certificate x509Cert = cryptoUtil.issueCertificate(new X500Name(intermediate.getSubject()), kpIntermediate, p10.getSubject(), p10.getSubjectPublicKeyInfo(), Calendar.YEAR, 1, gns, null, PKILevel.END_ENTITY);
Certificate cert = certUtil.createCertificate(x509Cert.getEncoded(), csr, "", false);
cert.setRevocationCA(caConfig);
certRepository.save(cert);
csrUtil.setCsrAttribute(csr, CsrAttribute.ATTRIBUTE_CA_PROCESSING_FINISHED_TIMESTAMP, "" + System.currentTimeMillis(), true);
csr.setStatus(CsrStatus.ISSUED);
csrRepository.save(csr);
return cert;
} catch (IOException e) {
LOG.info("Problem signing certificate request", e);
throw new GeneralSecurityException(e);
}
/*
RDN[] rdnArr = new RDN[csr.getRdns().size()];
int i = 0;
for(de.trustable.ca3s.core.domain.RDN rdn:csr.getRdns()) {
LOG.debug("RDN contains #{}", rdn.getRdnAttributes().size());
int attLen = rdn.getRdnAttributes().size();
AttributeTypeAndValue[] atavArr = new AttributeTypeAndValue[attLen];
int j = 0;
for(RDNAttribute rdnAtt: rdn.getRdnAttributes()) {
AttributeTypeAndValue atav = new AttributeTypeAndValue( rdnAtt.getAttributeType(), new DEROctetString(rdnAtt.getAttributeValue().getBytes()));
}
rdnArr[i++] = new RDN(atav);
}
X500Name subject = new X500Name(csr.getRdns());
*/
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project d3web-KnowWE by denkbares.
the class DOTRenderer method addTargetAttribute.
/**
* Adds the target-attribute to the element.
*
* @created 21.12.2013
*/
private static void addTargetAttribute(Element element) {
Attribute target = new Attribute("target", "_top");
element.setAttribute(target);
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project gridfour by gwlucastrig.
the class ExtractData method process.
void process(PrintStream ps, String product, String inputPath) throws IOException, InvalidRangeException {
// Open the NetCDF file -----------------------------------
ps.println("Reading data from " + inputPath);
NetcdfFile ncfile = NetcdfFile.open(inputPath);
// Inspect the content of the file ----------------------------
// Start with the high-level metadata elements that describe the
// entire file
ps.println("NetCDF File Type: " + ncfile.getFileTypeDescription());
ps.println("");
ps.println("Global attributes attached to file---------------------------");
List<Attribute> attributes = ncfile.getGlobalAttributes();
for (Attribute a : attributes) {
ps.println(a.toString());
}
// The content of NetCDF files is accessed through the use of the
// NetCDF class named Variable. Get all Variables defined in the
// current file and print a summary of their metadata to the text output.
// The Java NetCDF team implemented good "toString()" methods
// for the variable class. So printing their metadata is quite easy.
ps.println("");
ps.println("Variables found in file--------------------------------------");
List<Variable> variables = ncfile.getVariables();
for (Variable v : variables) {
ps.println("\n" + v.toString());
}
// Identify which Variable instances carry information about the
// geographic (latitude/longitude) coordinate system and also which
// carry information for elevation and bathymetry.
// In NetCDF, Variable instances area associated
// with arbitrary "name" attributes assigned to the objects
// when the data product is created. We can pull these variables
// out of the NetCDF file using their names. However,
// ETOPO1 and GEBCO_2019 use different Variable names to identify
// their content.
// the Variable that carries row-latitude information
Variable lat;
// the Variable that carries column-longitude information
Variable lon;
// the variable that carries elevation and bathymetry
Variable z;
// will be set to either "ETOPO1" or "GEBCO"
String label;
float[][] palette;
int reportingCount;
if (product.startsWith("ETOP")) {
label = "ETOPO1";
lat = ncfile.findVariable("y");
lon = ncfile.findVariable("x");
z = ncfile.findVariable("z");
palette = ExamplePalettes.paletteETOPO1;
reportingCount = 1000;
} else {
// the product is GEBCO
label = "GEBCO";
lat = ncfile.findVariable("lat");
lon = ncfile.findVariable("lon");
z = ncfile.findVariable("elevation");
palette = ExamplePalettes.paletteGEBCO;
reportingCount = 10000;
}
// using the variables from above, extract coordinate system
// information for the product and print it to the output.
// we will use this data below for computing the volume of the
// world's oceans.
ExtractionCoordinates coords = new ExtractionCoordinates(lat, lon);
coords.summarizeCoordinates(ps);
// Get the dimensions of the raster (grid) elevation/bathymetry data.
//
// NetCDF uses an concept named "rank" to define the rank of a
// Variable. A variable of rank 1 is essentially a vector (or one
// dimensional array). A variable of rank 2 has rows and columns,
// and is essentially a matrix. Higher rank variables are not uncommon.
//
// In ETOPO1 and GEBCO_2019, the elevation/bathymetry data is given
// as a raster (grid), so the rank will be two (for rows and columns).
// NetCDF data is always given in row-major order.
//
// NetCDF Variables also use the concept of "shape". In this case,
// the "shape" element tells you the number of rows and columns
// in the elevation variable.
// The getShape() method returns an array of integers dimensioned to
// the rank. Since the "z" variable is a raster, the return from
// getShape() will be an array of two values where shape[0] is
// the number of rows in the product and shape[1] is the number of
// columns.
// ETOPO1: 10800 rows and 21600 columns.
// GEBCO 2019: 43200 rows and 86400 columns
// In both these products, the rows are arranged from south-to-north,
// starting near the South Pole (-90 degrees) and ending near
// the North Pole (90 degrees).
// ETOPO1 has a uniform point spacing a 1-minute of arc.
// GEBCO has a uniform point spacing of 15-seconds of arc.
// Thus there are 4 times as many rows and 4 times as many columns
// in GEBCO versus ETOPO1.
int rank = z.getRank();
int[] shape = z.getShape();
int nRows = shape[0];
int nCols = shape[1];
ps.format("Rows: %8d%n", nRows);
ps.format("Columns: %8d%n", nCols);
// The output for this application is an image that is
// 720 pixels wide and 360 pixels high. Since the resulution of
// the two products is much higher than that, we need to compute a
// pixel scale value for down-sampling the source data.
// As we read the data, we will combine blocks of elevation/bathymetry
// values into a average value.
int imageHeight = 360;
int imageWidth = 720;
int pixelScale = nCols / imageWidth;
double[] sampleSum = new double[imageHeight * imageWidth];
ps.format("Down scaling data %d to 1 for image (%d values per pixel)%n", pixelScale, pixelScale * pixelScale);
// we also wish to collect the minimum and maximum values of the data.
double zMin = Double.POSITIVE_INFINITY;
double zMax = Double.NEGATIVE_INFINITY;
// naturally, the source data products contain far too many data values
// for us to read into memory all at once. We could read them one-at-a-time,
// but that would entail a lot of overhead and would slow processing
// considerably. So we read the data one-row-at-a-time.
// That pattern is not always to best for some products, but it works
// quite well for both ETOPO1 and GEBCO 2019.
// The readOrigin variable allows the application to specify where
// it wants to read the data from. The readShape variable tells
// NetCDF how many rows and columns to read.
int[] readOrigin = new int[rank];
int[] readShape = new int[rank];
// Finally, we are going to use the input data to estimate both the
// surface area and volume of the world's oceans. This calculation
// is not authoritative, and is performed here only to illustrate
// a potential use of the data. We perform the calculation by
// obtaining the surface area for each "cell" in the input raster
// (surface area per cell will vary by latitude). Then, if the sample
// is less than zero, we treat it as an ocean depth and add the
// computed area and volume to a running sum.
double areaSum = 0;
double volumeSum = 0;
double depthSum = 0;
long nDepth = 0;
long time0 = System.nanoTime();
for (int iRow = 0; iRow < nRows; iRow++) {
int imageRow = imageHeight - 1 - iRow / pixelScale;
double areaOfCellsInRow = coords.getAreaOfEachCellInRow(iRow);
if (iRow % reportingCount == 0) {
System.out.println("Processing row " + iRow);
}
int row0 = iRow;
int col0 = 0;
readOrigin[0] = row0;
readOrigin[1] = col0;
readShape[0] = 1;
readShape[1] = nCols;
Array array = z.read(readOrigin, readShape);
for (int iCol = 0; iCol < nCols; iCol++) {
int imageCol = iCol / pixelScale;
int index = imageRow * imageWidth + imageCol;
double sample = array.getDouble(iCol);
if (sample <= -32767) {
// neither ETOPO1 or GEBCO contain "no-data" points. However,
// there are some similar products that do. Treat these
// as not-a-number
sample = Float.NaN;
}
if (sample < zMin) {
zMin = sample;
}
if (sample > zMax) {
zMax = sample;
}
sampleSum[index] += sample;
if (sample < 0) {
// it's water
areaSum += areaOfCellsInRow;
volumeSum -= areaOfCellsInRow * sample / 1000.0;
depthSum -= sample;
nDepth++;
}
}
}
ncfile.close();
long time1 = System.nanoTime();
double deltaT = (time1 - time0) / 1.0e+9;
ps.format("Time to read input file %7.3f second%n", deltaT);
ps.format("Min Value: %7.3f meters%n", zMin);
ps.format("Max Value: %7.3f meters%n", zMax);
ps.format("Surface area of oceans %20.1f km^2%n", areaSum);
ps.format("Volume of oceans %20.1f km^3%n", volumeSum);
ps.format("Mean depth of oceans %20.1f m%n", depthSum / nDepth);
ps.flush();
int[] argb = new int[imageHeight * imageWidth];
float[] zPixel = new float[sampleSum.length];
double nCellsPerPixel = pixelScale * pixelScale;
for (int i = 0; i < sampleSum.length; i++) {
zPixel[i] = (float) (sampleSum[i] / nCellsPerPixel);
argb[i] = getRgb(palette, zPixel[i]);
}
String outputPath = "Test" + label + ".png";
File outputImage = new File(outputPath);
BufferedImage bImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
bImage.setRGB(0, 0, imageWidth, imageHeight, argb, 0, imageWidth);
Graphics graphics = bImage.getGraphics();
graphics.setColor(Color.darkGray);
graphics.drawRect(0, 0, imageWidth - 1, imageHeight - 1);
ImageIO.write(bImage, "PNG", outputImage);
// Shaded Relief demo ------------------------------------------------
// Create a shaded-relief demo by using a simple illumination model
// and applying Gridfour's B-Spline interpolator to compute the
// surface normal. The x and y scales that are needed by the interpolator
// are derived using the meters-per-pixel value which is computed from
// the radius of the earth and the number of pixels in the image.
// Because the distance across one degree of longitude decreases
// as the magnitude of the latitude increases, an adjustment is
// made to the xScale factor. Finally, a steeping factor is added to
// make the shading a bit more pronounced in the image.
//
// Specify the parameters for the illumination source (the "sun")
double ambient = 0.2;
double steepen = 50.0;
double sunAzimuth = Math.toRadians(145);
double sunElevation = Math.toRadians(60);
// create a unit vector pointing at illumination source
double cosA = Math.cos(sunAzimuth);
double sinA = Math.sin(sunAzimuth);
double cosE = Math.cos(sunElevation);
double sinE = Math.sin(sunElevation);
double xSun = cosA * cosE;
double ySun = sinA * cosE;
double zSun = sinE;
double yScale = Math.PI * earthRadiusM / imageHeight;
InterpolatorBSpline bSpline = new InterpolatorBSpline();
InterpolationResult result = new InterpolationResult();
for (int iRow = 0; iRow < imageHeight; iRow++) {
double yRow = iRow + 0.5;
double rowLatitude = 90 - 180.0 * yRow / imageHeight;
double xScale = yScale * Math.cos(Math.toRadians(rowLatitude));
for (int iCol = 0; iCol < imageWidth; iCol++) {
double xCol = iCol + 0.5;
bSpline.interpolate(yRow, xCol, imageHeight, imageWidth, zPixel, yScale, xScale, InterpolationTarget.FirstDerivatives, result);
// double z = result.z; not used, included for documentation
double nx = -result.zx * steepen;
double ny = result.zy * steepen;
double s = Math.sqrt(nx * nx + ny * ny + 1);
nx /= s;
ny /= s;
double nz = 1 / s;
double dot = nx * xSun + ny * ySun + nz * zSun;
double shade = ambient;
if (dot > 0) {
shade = dot * (1 - ambient) + ambient;
}
int index = iRow * imageWidth + iCol;
argb[index] = getRgb(palette, zPixel[index], shade);
}
}
outputPath = "ShadedRelief_" + label + ".png";
outputImage = new File(outputPath);
bImage = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_ARGB);
bImage.setRGB(0, 0, imageWidth, imageHeight, argb, 0, imageWidth);
graphics = bImage.getGraphics();
graphics.setColor(Color.darkGray);
graphics.drawRect(0, 0, imageWidth - 1, imageHeight - 1);
ImageIO.write(bImage, "PNG", outputImage);
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project box-c by UNC-Libraries.
the class SetDescriptiveMetadataFilter method extractCollectionId.
private void extractCollectionId(Element mods, IndexDocumentBean idb) {
List<Element> identifiers = mods.getChildren(COLLECTION_NUMBER_EL, JDOMNamespaceUtil.MODS_V3_NS);
String collectionId = null;
if (!identifiers.isEmpty()) {
for (Element aid : identifiers) {
Attribute type = aid.getAttribute("type");
Attribute collection = aid.getAttribute("displayLabel");
if (type == null || collection == null) {
continue;
}
if (collection.getValue().equals(COLLECTION_NUMBER_LABEL) && type.getValue().equals(COLLECTION_NUMBER_TYPE)) {
collectionId = aid.getValue();
break;
}
}
}
idb.setCollectionId(collectionId);
}
use of com.github.zhenwei.core.asn1.x509.Attribute in project vsp-playgrounds by matsim-vsp.
the class XMLWriter method addTransitRoute.
public void addTransitRoute(Element tline, TransitRoute troute) {
Element transitroute = new Element("transitRoute");
transitroute.setAttribute(new Attribute("id", troute.getID()));
List<Stop> routeprofile = troute.getRouteProfile();
List<Link> route = troute.getRoute();
List<Departure> departures = troute.getDepartures();
Element transportmode = new Element("transportMode");
// transportmode.addContent(routeprofile.get(0).getTransportMode());//get transport mode from the first stop
transportmode.addContent("pt");
Element rprof = new Element("routeProfile");
Element route_element = new Element("route");
Element departures_element = new Element("departures");
Iterator iter = routeprofile.iterator();
while (iter.hasNext()) {
Stop stop = (Stop) iter.next();
addStop(rprof, stop);
}
Iterator iter1 = route.iterator();
while (iter1.hasNext()) {
Link link = (Link) iter1.next();
addLink(route_element, link);
}
Iterator iter2 = departures.iterator();
while (iter2.hasNext()) {
Departure departure = (Departure) iter2.next();
addDeparture(departures_element, departure);
}
transitroute.addContent(transportmode);
transitroute.addContent(rprof);
// transitroute.addContent(route_element);
transitroute.addContent(departures_element);
tline.addContent(transitroute);
}
Aggregations