1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_xmlsecurity.hxx"
26 
27 #include <xmlsecurity/certvalidity.hxx>
28 #include <com/sun/star/security/CertificateValidity.hpp>
29 
30 using ::rtl::OUString ;
31 using namespace ::com::sun::star::security ;
32 
33 #define VALID_STR "valid certificate"
34 #define INVALID_STR "invalid certificate"
35 #define UNTRUSTED_STR "untrusted certificate"
36 #define TIME_INVALID_STR "expired certificate"
37 #define NOT_NESTED_TIME_STR "invalid time nesting"
38 #define REVOKED_STR "revoked certificate"
39 #define UNKNOWN_REVOKATION_STR "unknown certificate revocation status"
40 #define SIGNATURE_INVALID_STR "invalid certificate signature"
41 #define EXTENSION_INVALID_STR "invalid certificate extension"
42 #define EXTENSION_UNKNOWN_STR "unknown critical certificate extension"
43 #define ISSUER_UNKNOWN_STR "unknown certificate issuer"
44 #define ISSUER_UNTRUSTED_STR "untrusted certificate issuer"
45 #define ISSUER_INVALID_STR "invalid certificate issuer"
46 #define ROOT_UNKNOWN_STR "unknown root certificate"
47 #define ROOT_UNTRUSTED_STR "untrusted root certificate"
48 #define ROOT_INVALID_STR "invalid root certificate"
49 #define CHAIN_INCOMPLETE_STR "invalid certification path"
50 
certificateValidityToOUString(::sal_Int32 certValidity)51 rtl::OUString certificateValidityToOUString( ::sal_Int32 certValidity ) {
52 	OUString aValidity ;
53 
54 	if( (certValidity & CertificateValidity::VALID) == CertificateValidity::VALID ) {
55 		aValidity = OUString::createFromAscii( ( const char* )VALID_STR ) ;
56 	} else if( ( certValidity & CertificateValidity::INVALID ) == CertificateValidity::INVALID ) {
57 		 aValidity = OUString::createFromAscii( ( const char* )INVALID_STR ) ;
58 	} else if( ( certValidity &  CertificateValidity::UNTRUSTED ) ==  CertificateValidity::UNTRUSTED ) {
59 		 aValidity = OUString::createFromAscii( ( const char* )UNTRUSTED_STR ) ;
60 	} else if( ( certValidity & CertificateValidity::TIME_INVALID ) == CertificateValidity::TIME_INVALID ) {
61 		 aValidity = OUString::createFromAscii( ( const char* )TIME_INVALID_STR ) ;
62 	} else if( ( certValidity & CertificateValidity::NOT_TIME_NESTED ) == CertificateValidity::NOT_TIME_NESTED ) {
63 		 aValidity = OUString::createFromAscii( ( const char* )NOT_NESTED_TIME_STR ) ;
64 	} else if( ( certValidity & CertificateValidity::REVOKED ) == CertificateValidity::REVOKED ) {
65 		 aValidity = OUString::createFromAscii( ( const char* )REVOKED_STR ) ;
66 	} else if( ( certValidity &  CertificateValidity::UNKNOWN_REVOKATION ) == CertificateValidity::UNKNOWN_REVOKATION ) {
67 		 aValidity = OUString::createFromAscii( ( const char* )UNKNOWN_REVOKATION_STR ) ;
68 	} else if( ( certValidity &  CertificateValidity::SIGNATURE_INVALID ) == CertificateValidity::SIGNATURE_INVALID ) {
69 		 aValidity = OUString::createFromAscii( ( const char* )SIGNATURE_INVALID_STR ) ;
70 	} else if( ( certValidity &  CertificateValidity::EXTENSION_INVALID ) == CertificateValidity::EXTENSION_INVALID ) {
71 		 aValidity = OUString::createFromAscii( ( const char* )EXTENSION_INVALID_STR ) ;
72 	} else if( ( certValidity &  CertificateValidity::EXTENSION_UNKNOWN ) == CertificateValidity::EXTENSION_UNKNOWN ) {
73 		 aValidity = OUString::createFromAscii( ( const char* )EXTENSION_UNKNOWN_STR ) ;
74 	} else if( ( certValidity &  CertificateValidity::ISSUER_UNKNOWN ) == CertificateValidity::ISSUER_UNKNOWN ) {
75 		 aValidity = OUString::createFromAscii( ( const char* )ISSUER_UNKNOWN_STR ) ;
76 	} else if( ( certValidity &  CertificateValidity::ISSUER_UNTRUSTED ) == CertificateValidity::ISSUER_UNTRUSTED ) {
77 		 aValidity = OUString::createFromAscii( ( const char* )ISSUER_UNTRUSTED_STR ) ;
78 	} else if( ( certValidity &  CertificateValidity::ISSUER_INVALID ) == CertificateValidity::ISSUER_INVALID ) {
79 		 aValidity = OUString::createFromAscii( ( const char* )ISSUER_INVALID_STR ) ;
80 	} else if( ( certValidity &  CertificateValidity::ROOT_UNKNOWN ) == CertificateValidity::ROOT_UNKNOWN ) {
81 		 aValidity = OUString::createFromAscii( ( const char* )ROOT_UNKNOWN_STR ) ;
82 	} else if( ( certValidity &  CertificateValidity::ROOT_UNTRUSTED ) == CertificateValidity::ROOT_UNTRUSTED ) {
83 		 aValidity = OUString::createFromAscii( ( const char* )ROOT_UNTRUSTED_STR ) ;
84 	} else if( ( certValidity &  CertificateValidity::ROOT_INVALID ) == CertificateValidity::ROOT_INVALID ) {
85 		 aValidity = OUString::createFromAscii( ( const char* )ROOT_INVALID_STR ) ;
86 	} else if( ( certValidity &  CertificateValidity::CHAIN_INCOMPLETE ) == CertificateValidity::CHAIN_INCOMPLETE ) {
87 		 aValidity = OUString::createFromAscii( ( const char* )CHAIN_INCOMPLETE_STR ) ;
88 	} else {
89 		 aValidity = OUString::createFromAscii( ( const char* )INVALID_STR ) ;
90 	}
91 
92 	return aValidity ;
93 }
94 
95