use of ucar.nc2.Attribute in project JMRI by JMRI.
the class ControlPanel method setXml.
/**
* Set the preferences based on the XML Element.
* <ul>
* <li> Window prefs
* </ul>
*
*
* @param e The Element for this object.
*/
public void setXml(Element e) {
internalAdjust = true;
try {
this.setSpeedController(e.getAttribute("displaySpeedSlider").getIntValue());
} catch (org.jdom2.DataConversionException ex) {
log.error("DataConverstionException in setXml: " + ex);
} catch (Exception em) {
// in this case, recover by displaying the speed slider.
this.setSpeedController(SLIDERDISPLAY);
}
Attribute tsAtt = e.getAttribute("trackSlider");
if (tsAtt != null) {
try {
trackSlider = tsAtt.getBooleanValue();
} catch (org.jdom2.DataConversionException ex) {
trackSlider = trackSliderDefault;
}
} else {
trackSlider = trackSliderDefault;
}
Attribute tsmiAtt = e.getAttribute("trackSliderMinInterval");
if (tsmiAtt != null) {
try {
trackSliderMinInterval = tsmiAtt.getLongValue();
} catch (org.jdom2.DataConversionException ex) {
trackSliderMinInterval = trackSliderMinIntervalDefault;
}
if (trackSliderMinInterval < trackSliderMinIntervalMin) {
trackSliderMinInterval = trackSliderMinIntervalMin;
} else if (trackSliderMinInterval > trackSliderMinIntervalMax) {
trackSliderMinInterval = trackSliderMinIntervalMax;
}
} else {
trackSliderMinInterval = trackSliderMinIntervalDefault;
}
if ((prevShuntingFn == null) && (e.getAttribute("switchSliderOnFunction") != null)) {
setSwitchSliderFunction(e.getAttribute("switchSliderOnFunction").getValue());
}
internalAdjust = false;
Element window = e.getChild("window");
WindowPreferences.setPreferences(this, window);
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class SerialSignalHeadXml method load.
@Override
public boolean load(Element shared, Element perNode) {
String sys = shared.getAttribute("systemName").getValue();
Attribute a = shared.getAttribute("userName");
SignalHead h;
if (a == null) {
h = new SerialSignalHead(sys);
} else {
h = new SerialSignalHead(sys, a.getValue());
}
loadCommon(h, shared);
InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
return true;
}
use of ucar.nc2.Attribute in project android_frameworks_base by DirtyUnicorns.
the class ESTHandler method buildCSR.
private byte[] buildCSR(ByteBuffer octetBuffer, OMADMAdapter omadmAdapter, HTTPHandler httpHandler) throws IOException, GeneralSecurityException {
//Security.addProvider(new BouncyCastleProvider());
Log.d(TAG, "/csrattrs:");
/*
byte[] octets = new byte[octetBuffer.remaining()];
octetBuffer.duplicate().get(octets);
for (byte b : octets) {
System.out.printf("%02x ", b & 0xff);
}
*/
Collection<Asn1Object> csrs = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : csrs) {
Log.d(TAG, asn1Object.toString());
}
if (csrs.size() != 1) {
throw new IOException("Unexpected object count in CSR attributes response: " + csrs.size());
}
Asn1Object sequence = csrs.iterator().next();
if (sequence.getClass() != Asn1Constructed.class) {
throw new IOException("Unexpected CSR attribute container: " + sequence);
}
String keyAlgo = null;
Asn1Oid keyAlgoOID = null;
String sigAlgo = null;
String curveName = null;
Asn1Oid pubCrypto = null;
int keySize = -1;
Map<Asn1Oid, ASN1Encodable> idAttributes = new HashMap<>();
for (Asn1Object child : sequence.getChildren()) {
if (child.getTag() == Asn1Decoder.TAG_OID) {
Asn1Oid oid = (Asn1Oid) child;
OidMappings.SigEntry sigEntry = OidMappings.getSigEntry(oid);
if (sigEntry != null) {
sigAlgo = sigEntry.getSigAlgo();
keyAlgoOID = sigEntry.getKeyAlgo();
keyAlgo = OidMappings.getJCEName(keyAlgoOID);
} else if (oid.equals(OidMappings.sPkcs9AtChallengePassword)) {
byte[] tlsUnique = httpHandler.getTLSUnique();
if (tlsUnique != null) {
idAttributes.put(oid, new DERPrintableString(Base64.encodeToString(tlsUnique, Base64.DEFAULT)));
} else {
Log.w(TAG, "Cannot retrieve TLS unique channel binding");
}
}
} else if (child.getTag() == Asn1Decoder.TAG_SEQ) {
Asn1Oid oid = null;
Set<Asn1Oid> oidValues = new HashSet<>();
List<Asn1Object> values = new ArrayList<>();
for (Asn1Object attributeSeq : child.getChildren()) {
if (attributeSeq.getTag() == Asn1Decoder.TAG_OID) {
oid = (Asn1Oid) attributeSeq;
} else if (attributeSeq.getTag() == Asn1Decoder.TAG_SET) {
for (Asn1Object value : attributeSeq.getChildren()) {
if (value.getTag() == Asn1Decoder.TAG_OID) {
oidValues.add((Asn1Oid) value);
} else {
values.add(value);
}
}
}
}
if (oid == null) {
throw new IOException("Invalid attribute, no OID");
}
if (oid.equals(OidMappings.sExtensionRequest)) {
for (Asn1Oid subOid : oidValues) {
if (OidMappings.isIDAttribute(subOid)) {
if (subOid.equals(OidMappings.sMAC)) {
idAttributes.put(subOid, new DERIA5String(omadmAdapter.getMAC()));
} else if (subOid.equals(OidMappings.sIMEI)) {
idAttributes.put(subOid, new DERIA5String(omadmAdapter.getImei()));
} else if (subOid.equals(OidMappings.sMEID)) {
idAttributes.put(subOid, new DERBitString(omadmAdapter.getMeid()));
} else if (subOid.equals(OidMappings.sDevID)) {
idAttributes.put(subOid, new DERPrintableString(omadmAdapter.getDevID()));
}
}
}
} else if (OidMappings.getCryptoID(oid) != null) {
pubCrypto = oid;
if (!values.isEmpty()) {
for (Asn1Object value : values) {
if (value.getTag() == Asn1Decoder.TAG_INTEGER) {
keySize = (int) ((Asn1Integer) value).getValue();
}
}
}
if (oid.equals(OidMappings.sAlgo_EC)) {
if (oidValues.isEmpty()) {
throw new IOException("No ECC curve name provided");
}
for (Asn1Oid value : oidValues) {
curveName = OidMappings.getJCEName(value);
if (curveName != null) {
break;
}
}
if (curveName == null) {
throw new IOException("Found no ECC curve for " + oidValues);
}
}
}
}
}
if (keyAlgoOID == null) {
throw new IOException("No public key algorithm specified");
}
if (pubCrypto != null && !pubCrypto.equals(keyAlgoOID)) {
throw new IOException("Mismatching key algorithms");
}
if (keyAlgoOID.equals(OidMappings.sAlgo_RSA)) {
if (keySize < MinRSAKeySize) {
if (keySize >= 0) {
Log.i(TAG, "Upgrading suggested RSA key size from " + keySize + " to " + MinRSAKeySize);
}
keySize = MinRSAKeySize;
}
}
Log.d(TAG, String.format("pub key '%s', signature '%s', ECC curve '%s', id-atts %s", keyAlgo, sigAlgo, curveName, idAttributes));
/*
Ruckus:
SEQUENCE:
OID=1.2.840.113549.1.1.11 (algo_id_sha256WithRSAEncryption)
RFC-7030:
SEQUENCE:
OID=1.2.840.113549.1.9.7 (challengePassword)
SEQUENCE:
OID=1.2.840.10045.2.1 (algo_id_ecPublicKey)
SET:
OID=1.3.132.0.34 (secp384r1)
SEQUENCE:
OID=1.2.840.113549.1.9.14 (extensionRequest)
SET:
OID=1.3.6.1.1.1.1.22 (mac-address)
OID=1.2.840.10045.4.3.3 (eccdaWithSHA384)
1L, 3L, 6L, 1L, 1L, 1L, 1L, 22
*/
// ECC Does not appear to be supported currently
KeyPairGenerator kpg = KeyPairGenerator.getInstance(keyAlgo);
if (curveName != null) {
AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(keyAlgo);
algorithmParameters.init(new ECNamedCurveGenParameterSpec(curveName));
kpg.initialize(algorithmParameters.getParameterSpec(ECNamedCurveGenParameterSpec.class));
} else {
kpg.initialize(keySize);
}
KeyPair kp = kpg.generateKeyPair();
X500Principal subject = new X500Principal("CN=Android, O=Google, C=US");
mClientKey = kp.getPrivate();
// !!! Map the idAttributes into an ASN1Set of values to pass to
// the PKCS10CertificationRequest - this code is using outdated BC classes and
// has *not* been tested.
ASN1Set attributes;
if (!idAttributes.isEmpty()) {
ASN1EncodableVector payload = new DEREncodableVector();
for (Map.Entry<Asn1Oid, ASN1Encodable> entry : idAttributes.entrySet()) {
DERObjectIdentifier type = new DERObjectIdentifier(entry.getKey().toOIDString());
ASN1Set values = new DERSet(entry.getValue());
Attribute attribute = new Attribute(type, values);
payload.add(attribute);
}
attributes = new DERSet(payload);
} else {
attributes = null;
}
return new PKCS10CertificationRequest(sigAlgo, subject, kp.getPublic(), attributes, mClientKey).getEncoded();
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class IndicatorTurnoutIconXml method load.
/**
* Create a IndicatorTurnoutIcon, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o Editor as an Object
*/
@Override
public void load(Element element, Object o) {
// create the objects
Editor p = (Editor) o;
IndicatorTurnoutIcon l = new IndicatorTurnoutIcon(p);
Element name = element.getChild("turnout");
if (name == null) {
log.error("incorrect information for turnout; must use turnout name");
} else {
l.setTurnout(name.getText());
}
Element elem = element.getChild("iconmaps");
if (elem != null) {
List<Element> maps = elem.getChildren();
if (maps.size() > 0) {
for (int i = 0; i < maps.size(); i++) {
String status = maps.get(i).getName();
List<Element> states = maps.get(i).getChildren();
for (int k = 0; k < states.size(); k++) {
String msg = "IndicatorTurnout \"" + l.getNameString() + "\" icon \"" + states.get(k).getName() + "\" ";
NamedIcon icon = loadIcon(l, states.get(k).getName(), maps.get(i), msg, p);
if (icon != null) {
l.setIcon(status, states.get(k).getName(), icon);
} else {
log.info(msg + " removed for url= " + name);
return;
}
}
}
}
Attribute attr = elem.getAttribute("family");
if (attr != null) {
l.setFamily(attr.getValue());
}
}
name = element.getChild("occupancyblock");
if (name != null) {
l.setOccBlock(name.getText());
} else {
// only write sensor if no OBlock, don't write double sensing
name = element.getChild("occupancysensor");
if (name != null) {
l.setOccSensor(name.getText());
}
}
l.setShowTrain(false);
name = element.getChild("showTrainName");
if (name != null) {
if ("yes".equals(name.getText())) {
l.setShowTrain(true);
}
}
elem = element.getChild("paths");
if (elem != null) {
ArrayList<String> paths = new ArrayList<String>();
List<Element> pth = elem.getChildren();
for (int i = 0; i < pth.size(); i++) {
paths.add(pth.get(i).getText());
}
l.setPaths(paths);
}
l.updateSize();
p.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, Editor.TURNOUTS, element);
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class PositionableShapeXml method loadCommonAttributes.
public void loadCommonAttributes(PositionableShape ps, int defaultLevel, Element element) {
int x = getInt(element, "x");
int y = getInt(element, "y");
ps.setLocation(x, y);
ps.setDisplayLevel(getInt(element, "level"));
Attribute a = element.getAttribute("hidden");
if ((a != null) && a.getValue().equals("yes")) {
ps.setHidden(true);
ps.setVisible(false);
}
a = element.getAttribute("positionable");
if ((a != null) && a.getValue().equals("true")) {
ps.setPositionable(true);
} else {
ps.setPositionable(false);
}
a = element.getAttribute("showtooltip");
if ((a != null) && a.getValue().equals("true")) {
ps.setShowTooltip(true);
} else {
ps.setShowTooltip(false);
}
a = element.getAttribute("editable");
if ((a != null) && a.getValue().equals("true")) {
ps.setEditable(true);
} else {
ps.setEditable(false);
}
Element elem = element.getChild("toolTip");
if (elem != null) {
ToolTip tip = ps.getTooltip();
if (tip != null) {
tip.setText(elem.getText());
}
}
ps.setLineWidth(getInt(element, "lineWidth"));
int alpha = -1;
try {
a = element.getAttribute("alpha");
if (a != null) {
alpha = a.getIntValue();
}
} catch (DataConversionException ex) {
log.warn("invalid 'alpha' value (non integer)");
}
ps.setLineColor(getColor(element, "lineColor", alpha));
ps.setFillColor(getColor(element, "fillColor", alpha));
ps.makeShape();
ps.rotate(getInt(element, "degrees"));
a = element.getAttribute("hideOnSensor");
boolean hide = false;
if (a != null) {
hide = a.getValue().equals("true");
}
int changeLevel = -1;
try {
changeLevel = getInt(element, "changeLevelOnSensor");
} catch (Exception e) {
log.error("failed to get changeLevel attribute ex= " + e);
}
try {
Attribute attr = element.getAttribute("controlSensor");
if (attr != null) {
ps.setControlSensor(attr.getValue(), hide, changeLevel);
}
} catch (NullPointerException e) {
log.error("incorrect information for controlSensor of PositionableShape");
}
ps.updateSize();
}
Aggregations