You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GpgSignatureVerifier.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. * Copyright (C) 2021, Thomas Wolf <thomas.wolf@paranor.ch> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.lib;
  11. import java.io.IOException;
  12. import java.util.Date;
  13. import org.eclipse.jgit.annotations.NonNull;
  14. import org.eclipse.jgit.annotations.Nullable;
  15. import org.eclipse.jgit.api.errors.JGitInternalException;
  16. import org.eclipse.jgit.revwalk.RevObject;
  17. /**
  18. * A {@code GpgVerifier} can verify GPG signatures on git commits and tags.
  19. *
  20. * @since 5.11
  21. */
  22. public interface GpgSignatureVerifier {
  23. /**
  24. * Verifies the signature on a signed commit or tag.
  25. *
  26. * @param object
  27. * to verify
  28. * @param config
  29. * the {@link GpgConfig} to use
  30. * @return a {@link SignatureVerification} describing the outcome of the
  31. * verification, or {@code null} if the object was not signed
  32. * @throws IOException
  33. * if an error occurs getting a public key
  34. * @throws org.eclipse.jgit.api.errors.JGitInternalException
  35. * if signature verification fails
  36. */
  37. @Nullable
  38. SignatureVerification verifySignature(@NonNull RevObject object,
  39. @NonNull GpgConfig config) throws IOException;
  40. /**
  41. * Verifies a given signature for given data.
  42. *
  43. * @param data
  44. * the signature is for
  45. * @param signatureData
  46. * the ASCII-armored signature
  47. * @return a {@link SignatureVerification} describing the outcome
  48. * @throws IOException
  49. * if the signature cannot be parsed
  50. * @throws JGitInternalException
  51. * if signature verification fails
  52. */
  53. public SignatureVerification verify(byte[] data, byte[] signatureData)
  54. throws IOException;
  55. /**
  56. * Retrieves the name of this verifier. This should be a short string
  57. * identifying the engine that verified the signature, like "gpg" if GPG is
  58. * used, or "bc" for a BouncyCastle implementation.
  59. *
  60. * @return the name
  61. */
  62. @NonNull
  63. String getName();
  64. /**
  65. * A {@link GpgSignatureVerifier} may cache public keys to speed up
  66. * verifying signatures on multiple objects. This clears this cache, if any.
  67. */
  68. void clear();
  69. /**
  70. * A {@code SignatureVerification} returns data about a (positively or
  71. * negatively) verified signature.
  72. */
  73. interface SignatureVerification {
  74. // Data about the signature.
  75. @NonNull
  76. Date getCreationDate();
  77. // Data from the signature used to find a public key.
  78. /**
  79. * Obtains the signer as stored in the signature, if known.
  80. *
  81. * @return the signer, or {@code null} if unknown
  82. */
  83. String getSigner();
  84. /**
  85. * Obtains the short or long fingerprint of the public key as stored in
  86. * the signature, if known.
  87. *
  88. * @return the fingerprint, or {@code null} if unknown
  89. */
  90. String getKeyFingerprint();
  91. // Some information about the found public key.
  92. /**
  93. * Obtains the OpenPGP user ID associated with the key.
  94. *
  95. * @return the user id, or {@code null} if unknown
  96. */
  97. String getKeyUser();
  98. /**
  99. * Tells whether the public key used for this signature verification was
  100. * expired when the signature was created.
  101. *
  102. * @return {@code true} if the key was expired already, {@code false}
  103. * otherwise
  104. */
  105. boolean isExpired();
  106. /**
  107. * Obtains the trust level of the public key used to verify the
  108. * signature.
  109. *
  110. * @return the trust level
  111. */
  112. @NonNull
  113. TrustLevel getTrustLevel();
  114. // The verification result.
  115. /**
  116. * Tells whether the signature verification was successful.
  117. *
  118. * @return {@code true} if the signature was verified successfully;
  119. * {@code false} if not.
  120. */
  121. boolean getVerified();
  122. /**
  123. * Obtains a human-readable message giving additional information about
  124. * the outcome of the verification.
  125. *
  126. * @return the message, or {@code null} if none set.
  127. */
  128. String getMessage();
  129. }
  130. /**
  131. * The owner's trust in a public key.
  132. */
  133. enum TrustLevel {
  134. UNKNOWN, NEVER, MARGINAL, FULL, ULTIMATE
  135. }
  136. }