CordovaClientCertRequest.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. Licensed to the Apache Software Foundation (ASF) under one
  3. or more contributor license agreements. See the NOTICE file
  4. distributed with this work for additional information
  5. regarding copyright ownership. The ASF licenses this file
  6. to you under the Apache License, Version 2.0 (the
  7. "License"); you may not use this file except in compliance
  8. with the License. You may obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing,
  11. software distributed under the License is distributed on an
  12. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  13. KIND, either express or implied. See the License for the
  14. specific language governing permissions and limitations
  15. under the License.
  16. */
  17. package org.apache.cordova;
  18. import java.security.Principal;
  19. import java.security.PrivateKey;
  20. import java.security.cert.X509Certificate;
  21. import android.annotation.SuppressLint;
  22. import android.webkit.ClientCertRequest;
  23. /**
  24. * Implementation of the ICordovaClientCertRequest for Android WebView.
  25. *
  26. */
  27. public class CordovaClientCertRequest implements ICordovaClientCertRequest {
  28. private final ClientCertRequest request;
  29. public CordovaClientCertRequest(ClientCertRequest request) {
  30. this.request = request;
  31. }
  32. /**
  33. * Cancel this request
  34. */
  35. @SuppressLint("NewApi")
  36. public void cancel()
  37. {
  38. request.cancel();
  39. }
  40. /*
  41. * Returns the host name of the server requesting the certificate.
  42. */
  43. @SuppressLint("NewApi")
  44. public String getHost()
  45. {
  46. return request.getHost();
  47. }
  48. /*
  49. * Returns the acceptable types of asymmetric keys (can be null).
  50. */
  51. @SuppressLint("NewApi")
  52. public String[] getKeyTypes()
  53. {
  54. return request.getKeyTypes();
  55. }
  56. /*
  57. * Returns the port number of the server requesting the certificate.
  58. */
  59. @SuppressLint("NewApi")
  60. public int getPort()
  61. {
  62. return request.getPort();
  63. }
  64. /*
  65. * Returns the acceptable certificate issuers for the certificate matching the private key (can be null).
  66. */
  67. @SuppressLint("NewApi")
  68. public Principal[] getPrincipals()
  69. {
  70. return request.getPrincipals();
  71. }
  72. /*
  73. * Ignore the request for now. Do not remember user's choice.
  74. */
  75. @SuppressLint("NewApi")
  76. public void ignore()
  77. {
  78. request.ignore();
  79. }
  80. /*
  81. * Proceed with the specified private key and client certificate chain. Remember the user's positive choice and use it for future requests.
  82. *
  83. * @param privateKey The privateKey
  84. * @param chain The certificate chain
  85. */
  86. @SuppressLint("NewApi")
  87. public void proceed(PrivateKey privateKey, X509Certificate[] chain)
  88. {
  89. request.proceed(privateKey, chain);
  90. }
  91. }