public static Optional<NSObject> optional(NSDictionary dictionary, String key) { return dictionary.containsKey(key) ? Optional.of(dictionary.get(key)) : Optional.empty(); }
public static Optional<NSObject> get(NSDictionary dictionary, String key) { return dictionary.containsKey(key) ? Optional.of(dictionary.get(key)) : Optional.empty(); }
@Deprecated public static <T extends NSObject> T fetchOrDefault(NSDictionary dictionary, String key, T defaultValue) throws BadDataException { return dictionary.containsKey(key) ? cast(key, dictionary) : defaultValue; }
@Deprecated public static <T extends NSObject> T fetch(NSDictionary dictionary, String key) throws BadDataException { if (dictionary.containsKey(key)) { return cast(key, dictionary); } throw new BadDataException("Missing key: " + key); }
private PairSetupPin3Response doPairSetupPin3(Socket socket, final byte[] sessionKeyHashK) throws Exception { MessageDigest sha512Digest = MessageDigest.getInstance("SHA-512"); sha512Digest.update("Pair-Setup-AES-Key".getBytes(StandardCharsets.UTF_8)); sha512Digest.update(sessionKeyHashK); byte[] aesKey = Arrays.copyOfRange(sha512Digest.digest(), 0, 16); sha512Digest.update("Pair-Setup-AES-IV".getBytes(StandardCharsets.UTF_8)); sha512Digest.update(sessionKeyHashK); byte[] aesIV = Arrays.copyOfRange(sha512Digest.digest(), 0, 16); int lengthB; int lengthA = lengthB = aesIV.length - 1; for (; lengthB >= 0 && 256 == ++aesIV[lengthA]; lengthA = lengthB += -1) ; Cipher aesGcm128Encrypt = Cipher.getInstance("AES/GCM/NoPadding"); SecretKeySpec secretKey = new SecretKeySpec(aesKey, "AES"); aesGcm128Encrypt.init(Cipher.ENCRYPT_MODE, secretKey, new GCMParameterSpec(128, aesIV)); final byte[] aesGcm128ClientLTPK = aesGcm128Encrypt.doFinal(authKey.getAbyte()); byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, byte[]>() {{ put("epk", Arrays.copyOfRange(aesGcm128ClientLTPK, 0, aesGcm128ClientLTPK.length - 16)); put("authTag", Arrays.copyOfRange(aesGcm128ClientLTPK, aesGcm128ClientLTPK.length - 16, aesGcm128ClientLTPK.length)); }}); byte[] pairSetupPin3ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData); NSDictionary pairSetupPin3Response = (NSDictionary) PropertyListParser.parse(pairSetupPin3ResponseBytes); if (pairSetupPin3Response.containsKey("epk") && pairSetupPin3Response.containsKey("authTag")) { byte[] epk = ((NSData) pairSetupPin3Response.get("epk")).bytes(); byte[] authTag = ((NSData) pairSetupPin3Response.get("authTag")).bytes(); return new PairSetupPin3Response(epk, authTag); } throw new Exception(); }
private PairSetupPin1Response doPairSetupPin1(Socket socket) throws Exception { byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, String>() {{ put("method", "pin"); put("user", clientId); }}); byte[] pairSetupPin1ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData); NSDictionary pairSetupPin1Response = (NSDictionary) PropertyListParser.parse(pairSetupPin1ResponseBytes); if (pairSetupPin1Response.containsKey("pk") && pairSetupPin1Response.containsKey("salt")) { byte[] pk = ((NSData) pairSetupPin1Response.get("pk")).bytes(); byte[] salt = ((NSData) pairSetupPin1Response.get("salt")).bytes(); return new PairSetupPin1Response(pk, salt); } throw new Exception(); }
private PairSetupPin2Response doPairSetupPin2(Socket socket, final byte[] publicClientValueA, final byte[] clientEvidenceMessageM1) throws Exception { byte[] pairSetupPinRequestData = AuthUtils.createPList(new HashMap<String, byte[]>() {{ put("pk", publicClientValueA); put("proof", clientEvidenceMessageM1); }}); byte[] pairSetupPin2ResponseBytes = AuthUtils.postData(socket, "/pair-setup-pin", "application/x-apple-binary-plist", pairSetupPinRequestData); NSDictionary pairSetupPin2Response = (NSDictionary) PropertyListParser.parse(pairSetupPin2ResponseBytes); if (pairSetupPin2Response.containsKey("proof")) { byte[] proof = ((NSData) pairSetupPin2Response.get("proof")).bytes(); return new PairSetupPin2Response(proof); } throw new Exception(); }