|
| 1 | +/* |
| 2 | + * Copyright 2024 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.android.keyattestation.verifier |
| 18 | + |
| 19 | +import com.google.common.flogger.GoogleLogger |
| 20 | +import com.google.errorprone.annotations.ThreadSafe |
| 21 | +import com.google.protobuf.ByteString |
| 22 | + |
| 23 | +/** A [LogHook] that logs to GoogleLogger. */ |
| 24 | +@ThreadSafe |
| 25 | +class GoogleLoggerLogHook : LogHook { |
| 26 | + override fun createRequestLog(): VerifyRequestLog = GoogleLoggerRequestLog(logger) |
| 27 | + |
| 28 | + internal companion object { |
| 29 | + val logger = GoogleLogger.forEnclosingClass() |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +@ThreadSafe |
| 34 | +private class GoogleLoggerRequestLog(private val logger: GoogleLogger) : VerifyRequestLog { |
| 35 | + override fun logInputChain(inputChain: List<ByteString>) {} |
| 36 | + |
| 37 | + override fun logResult(result: VerificationResult) { |
| 38 | + when (result) { |
| 39 | + is VerificationResult.Success -> logger.atInfo().log("Attestation verification succeeded.") |
| 40 | + is VerificationResult.ChallengeMismatch -> |
| 41 | + logger.atWarning().log("Attestation challenge mismatch.") |
| 42 | + is VerificationResult.PathValidationFailure -> |
| 43 | + logger.atWarning().withCause(result.cause).log("Certificate path validation failed.") |
| 44 | + is VerificationResult.ChainParsingFailure -> |
| 45 | + logger.atWarning().withCause(result.cause).log("Failed to parse certificate chain.") |
| 46 | + is VerificationResult.ExtensionParsingFailure -> |
| 47 | + logger.atWarning().withCause(result.cause).log("Failed to parse key description extension.") |
| 48 | + is VerificationResult.ExtensionConstraintViolation -> |
| 49 | + logger.atWarning().log("Constraint violation: %s", result.cause) |
| 50 | + is VerificationResult.SoftwareAttestationUnsupported -> {} |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + override fun logKeyDescription(keyDescription: KeyDescription) {} |
| 55 | + |
| 56 | + override fun logProvisioningInfoMap(provisioningInfoMap: ProvisioningInfoMap) {} |
| 57 | + |
| 58 | + override fun logCertSerialNumbers(certSerialNumbers: List<String>) {} |
| 59 | + |
| 60 | + override fun logInfoMessage(infoMessage: String) {} |
| 61 | + |
| 62 | + override fun flush() {} |
| 63 | +} |
0 commit comments