| // Copyright 2026 Google LLC | |
| // | |
| // 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 | |
| // | |
| // https://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. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_COSE_SIMPLE_CMS_PARSER_H_ | |
| #define THIRD_PARTY_CREDENTIO_COSE_SIMPLE_CMS_PARSER_H_ | |
| #include <memory> | |
| #include <string> | |
| #include <vector> | |
| #include "absl/status/status.h" | |
| #include "absl/status/statusor.h" | |
| #include "absl/strings/string_view.h" | |
| #include "crypto/algorithms.h" | |
| #include "crypto/default/cms/cms_parser.h" | |
| #include "openssl/stack.h" | |
| #include "openssl/x509.h" | |
| #include "tsp/cms_parser.h" | |
| #include "tsp/parsed_timestamp_token.h" | |
| namespace credentio { | |
| // ParsedTimestampToken implementation backed by the SimpleCMS library | |
| class SimpleParsedTimestampToken : public ParsedTimestampToken { | |
| public: | |
| static absl::StatusOr<std::unique_ptr<SimpleParsedTimestampToken>> Create( | |
| absl::string_view timestamp_token); | |
| // SimpleParsedTimestampToken is self-referential (cms_ contains pointers into | |
| // data_). Copying or moving this object would invalidate those pointers. | |
| SimpleParsedTimestampToken(const SimpleParsedTimestampToken&) = delete; | |
| SimpleParsedTimestampToken& operator=(const SimpleParsedTimestampToken&) = | |
| delete; | |
| ~SimpleParsedTimestampToken() override = default; | |
| absl::Status VerifySignature() const override; | |
| absl::StatusOr<HashAlgorithm> GetMessageImprintHashAlgorithm() const override; | |
| absl::StatusOr<std::vector<std::string>> GetCertificateChain() const override; | |
| absl::StatusOr<absl::string_view> GetSigningCertificateV2Bytes() | |
| const override; | |
| absl::StatusOr<absl::string_view> GetTstInfoBytes() const override; | |
| private: | |
| explicit SimpleParsedTimestampToken(absl::string_view data); | |
| absl::StatusOr<const credentio_cms::SignerInfo*> GetSingleSignerInfo() const; | |
| absl::StatusOr<X509*> GetSignerCert( | |
| const STACK_OF(X509) * certs, | |
| const credentio_cms::SignerInfo& signer_info) const; | |
| const std::string data_; | |
| credentio_cms::Content cms_; | |
| }; | |
| // CmsParser implementation backed by the SimpleCMS library | |
| // (//third_party/simple_cms). | |
| class SimpleCmsParser : public CmsParser { | |
| public: | |
| absl::StatusOr<std::unique_ptr<ParsedTimestampToken>> ParseTimestampToken( | |
| absl::string_view timestamp_token) const override; | |
| }; | |
| } // namespace credentio | |
| #endif // THIRD_PARTY_CREDENTIO_COSE_SIMPLE_CMS_PARSER_H_ |