/* * Copyright (C) 2009 Google Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.polo.pairing; import com.google.polo.exception.PoloException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.cert.Certificate; import java.security.interfaces.RSAPublicKey; import java.util.Arrays; /** * Class to represent the out-of-band secret transmitted during pairing. */ public class PoloChallengeResponse { /** * Hash algorithm to generate secret. */ private static final String HASH_ALGORITHM = "SHA-256"; /** * Optional handler for debug log messages. */ private DebugLogger mLogger; /** * Certificate of the local peer in the protocol. */ private Certificate mClientCertificate; /** * Certificate of the remote peer in the protocol. */ private Certificate mServerCertificate; /** * Creates a new callenge-response generator object. * * @param clientCert the certificate of the client node * @param serverCert the certificate of the server node * @param logger a listener for debugging messages; may be null */ public PoloChallengeResponse(Certificate clientCert, Certificate serverCert, DebugLogger logger) { mClientCertificate = clientCert; mServerCertificate = serverCert; mLogger = logger; } /** * Returns the alpha value to be used in pairing. *

* From the Polo design document, `alpha` is the value h(K_a | K_b | R_a): * for an RSA public key, that is: *