/src/libreoffice/include/svl/sigstruct.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #ifndef INCLUDED_XMLSECURITY_INC_SIGSTRUCT_HXX |
21 | | #define INCLUDED_XMLSECURITY_INC_SIGSTRUCT_HXX |
22 | | |
23 | | #include <rtl/ustring.hxx> |
24 | | #include <com/sun/star/util/DateTime.hpp> |
25 | | #include <com/sun/star/xml/crypto/SecurityOperationStatus.hpp> |
26 | | #include <com/sun/star/xml/crypto/DigestID.hpp> |
27 | | #include <com/sun/star/uno/Sequence.hxx> |
28 | | |
29 | | #include <set> |
30 | | #include <vector> |
31 | | |
32 | | namespace com::sun::star::graphic { class XGraphic; } |
33 | | |
34 | | /* |
35 | | * type of reference |
36 | | */ |
37 | | enum class SignatureReferenceType |
38 | | { |
39 | | SAMEDOCUMENT = 1, |
40 | | BINARYSTREAM = 2, |
41 | | XMLSTREAM = 3 |
42 | | }; |
43 | | |
44 | | struct SignatureReferenceInformation |
45 | | { |
46 | | SignatureReferenceType nType; |
47 | | OUString ouURI; |
48 | | // For ODF: XAdES digests (SHA256) or the old SHA1, from css::xml::crypto::DigestID |
49 | | sal_Int32 nDigestID; |
50 | | OUString ouDigestValue; |
51 | | /// Type of the reference: a URI (newer idSignedProperties references) or empty. |
52 | | OUString ouType; |
53 | | |
54 | | SignatureReferenceInformation() : |
55 | | nType(SignatureReferenceType::SAMEDOCUMENT), |
56 | | nDigestID(css::xml::crypto::DigestID::SHA1) |
57 | 0 | { |
58 | 0 | } |
59 | | |
60 | | SignatureReferenceInformation( SignatureReferenceType type, sal_Int32 digestID, const OUString& uri, const OUString& rType ) : |
61 | | SignatureReferenceInformation() |
62 | 0 | { |
63 | 0 | nType = type; |
64 | 0 | nDigestID = digestID; |
65 | 0 | ouURI = uri; |
66 | 0 | ouType = rType; |
67 | 0 | } |
68 | | }; |
69 | | |
70 | | typedef ::std::vector< SignatureReferenceInformation > SignatureReferenceInformations; |
71 | | |
72 | | namespace svl::crypto |
73 | | { |
74 | | /// Specifies the algorithm used for signature generation and validation. |
75 | | enum class SignatureMethodAlgorithm |
76 | | { |
77 | | RSA, |
78 | | ECDSA |
79 | | }; |
80 | | } |
81 | | |
82 | | |
83 | | struct SignatureInformation |
84 | | { |
85 | | sal_Int32 nSecurityId; |
86 | | css::xml::crypto::SecurityOperationStatus nStatus; |
87 | | SignatureReferenceInformations vSignatureReferenceInfors; |
88 | | struct X509CertInfo |
89 | | { |
90 | | OUString X509IssuerName; |
91 | | OUString X509SerialNumber; |
92 | | OUString X509Certificate; |
93 | | /// OOXML certificate SHA-256 digest, empty for ODF except when doing XAdES signature. |
94 | | OUString CertDigest; |
95 | | /// The certificate owner (aka subject). |
96 | | OUString X509Subject; |
97 | | }; |
98 | | typedef std::vector<X509CertInfo> X509Data; |
99 | | // note: at parse time, it's unknown which one is the signing certificate; |
100 | | // ImplVerifySignatures() figures it out and puts it at the back |
101 | | std::vector<X509Data> X509Datas; |
102 | | |
103 | | X509CertInfo const* GetSigningCertificate() const |
104 | 0 | { |
105 | 0 | if (X509Datas.empty()) |
106 | 0 | { |
107 | 0 | return nullptr; |
108 | 0 | } |
109 | 0 | assert(!X509Datas.back().empty()); |
110 | 0 | return & X509Datas.back().back(); |
111 | 0 | } |
112 | | |
113 | | OUString ouGpgKeyID; |
114 | | OUString ouGpgCertificate; |
115 | | OUString ouGpgOwner; |
116 | | |
117 | | OUString ouSignatureValue; |
118 | | css::util::DateTime stDateTime; |
119 | | |
120 | | // XAdES EncapsulatedX509Certificate values |
121 | | std::set<OUString> maEncapsulatedX509Certificates; |
122 | | |
123 | | OUString ouSignatureId; |
124 | | // signature may contain multiple time stamps - check they're consistent |
125 | | bool hasInconsistentSigningTime = false; |
126 | | //We also keep the date and time as string. This is done when this |
127 | | //structure is created as a result of a XML signature being read. |
128 | | //When then a signature is added or another removed, then the original |
129 | | //XML signatures are written again (unless they have been removed). |
130 | | //If the date time string is converted into the DateTime structure |
131 | | //then information can be lost because it only holds a fractional |
132 | | //of a second with an accuracy of one hundredth of second. |
133 | | //If the string contains |
134 | | //milliseconds (because the document was created by an application other than OOo) |
135 | | //and the converted time is written back, then the string looks different |
136 | | //and the signature is broken. |
137 | | OUString ouDateTime; |
138 | | /// The Id attribute of the <SignatureProperty> element that contains the <dc:date>. |
139 | | OUString ouDateTimePropertyId; |
140 | | /// Characters of the <dc:description> element inside the signature. |
141 | | OUString ouDescription; |
142 | | /// The Id attribute of the <SignatureProperty> element that contains the <dc:description>. |
143 | | OUString ouDescriptionPropertyId; |
144 | | /// Valid and invalid signature line images |
145 | | css::uno::Reference<css::graphic::XGraphic> aValidSignatureImage; |
146 | | css::uno::Reference<css::graphic::XGraphic> aInvalidSignatureImage; |
147 | | /// Signature Line Id, used to map signatures to their respective signature line images. |
148 | | OUString ouSignatureLineId; |
149 | | /// A full OOXML signature for unchanged roundtrip, empty for ODF. |
150 | | css::uno::Sequence<sal_Int8> aSignatureBytes; |
151 | | /// For PDF: digest format, from css::xml::crypto::DigestID |
152 | | sal_Int32 nDigestID; |
153 | | /// For PDF: has id-aa-signingCertificateV2 as a signed attribute. |
154 | | bool bHasSigningCertificate; |
155 | | /// For PDF: the byte range doesn't cover the whole document. |
156 | | bool bPartialDocumentSignature; |
157 | | |
158 | | svl::crypto::SignatureMethodAlgorithm eAlgorithmID; |
159 | | |
160 | | SignatureInformation( sal_Int32 nId ) |
161 | 0 | { |
162 | 0 | nSecurityId = nId; |
163 | 0 | nStatus = css::xml::crypto::SecurityOperationStatus_UNKNOWN; |
164 | 0 | nDigestID = 0; |
165 | 0 | bHasSigningCertificate = false; |
166 | 0 | bPartialDocumentSignature = false; |
167 | 0 | eAlgorithmID = svl::crypto::SignatureMethodAlgorithm::RSA; |
168 | 0 | } |
169 | | }; |
170 | | |
171 | | typedef ::std::vector< SignatureInformation > SignatureInformations; |
172 | | |
173 | | #endif |
174 | | |
175 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |