SanCertExt.cxx (c82f2877) SanCertExt.cxx (b7cf1532)
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

--- 23 unchanged lines hidden (view full) ---

32#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
33#include <com/sun/star/security/XCertificate.hpp>
34#include <com/sun/star/lang/XMultiServiceFactory.hpp>
35#include <com/sun/star/beans/NamedValue.hpp>
36#include "com/sun/star/uno/XComponentContext.hpp"
37#include "com/sun/star/uno/Reference.hxx"
38
39#include "cppuhelper/bootstrap.hxx"
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

--- 23 unchanged lines hidden (view full) ---

32#include <com/sun/star/xml/crypto/XXMLSecurityContext.hpp>
33#include <com/sun/star/security/XCertificate.hpp>
34#include <com/sun/star/lang/XMultiServiceFactory.hpp>
35#include <com/sun/star/beans/NamedValue.hpp>
36#include "com/sun/star/uno/XComponentContext.hpp"
37#include "com/sun/star/uno/Reference.hxx"
38
39#include "cppuhelper/bootstrap.hxx"
40#include "cppunit/TestAssert.h"
41#include "cppunit/TestFixture.h"
42#include "cppunit/extensions/HelperMacros.h"
43#include "cppunit/plugin/TestPlugIn.h"
40#include "gtest/gtest.h"
44#include "sal/types.h"
45#include "comphelper/sequence.hxx"
46#include <rtl/ustring.hxx>
47
48#include <neon/ne_ssl.h>
49
50using namespace com::sun::star;
51
52#define OID_SUBJECT_ALTERNATIVE_NAME "2.5.29.17"
53#define SEINITIALIZER_COMPONENT "com.sun.star.xml.crypto.SEInitializer"
54
55
56namespace {
57
41#include "sal/types.h"
42#include "comphelper/sequence.hxx"
43#include <rtl/ustring.hxx>
44
45#include <neon/ne_ssl.h>
46
47using namespace com::sun::star;
48
49#define OID_SUBJECT_ALTERNATIVE_NAME "2.5.29.17"
50#define SEINITIALIZER_COMPONENT "com.sun.star.xml.crypto.SEInitializer"
51
52
53namespace {
54
58 class Test: public CppUnit::TestFixture {
55 class Test: public ::testing::Test {
59
56
60 private:
57 protected:
61 static uno::Sequence< security::CertAltNameEntry > altNames;
62 static bool runOnce;
63
64 uno::Reference< xml::crypto::XSecurityEnvironment > initUno();
65 void init();
66 rtl::OString getB64CertFromFile(const char filename[]);
67 test::OfficeConnection connection_;
68
69 public:
70
71 Test();
72
73 ~Test();
74
58 static uno::Sequence< security::CertAltNameEntry > altNames;
59 static bool runOnce;
60
61 uno::Reference< xml::crypto::XSecurityEnvironment > initUno();
62 void init();
63 rtl::OString getB64CertFromFile(const char filename[]);
64 test::OfficeConnection connection_;
65
66 public:
67
68 Test();
69
70 ~Test();
71
75 virtual void setUp();
72 virtual void SetUp();
76
73
77 virtual void tearDown();
78
79 void test_Others();
80
81 void test_RFC822();
82
83 void test_DNS();
84
85 void test_Direcory();
86
87 void test_URI();
88
89 void test_IP();
90
91 void test_RID();
92
93 void test_EDI();
94
95 void test_X400();
96
97 CPPUNIT_TEST_SUITE(Test);
98 CPPUNIT_TEST(test_Others);
99 CPPUNIT_TEST(test_RFC822);
100 CPPUNIT_TEST(test_DNS);
101 CPPUNIT_TEST(test_Direcory);
102 CPPUNIT_TEST(test_URI);
103 CPPUNIT_TEST(test_IP);
104 CPPUNIT_TEST(test_RID);
105 CPPUNIT_TEST(test_EDI);
106 CPPUNIT_TEST(test_X400);
107 CPPUNIT_TEST_SUITE_END();
74 virtual void TearDown();
108 };
109
110 uno::Sequence< security::CertAltNameEntry > Test::altNames;
111 bool Test::runOnce = false;
112
75 };
76
77 uno::Sequence< security::CertAltNameEntry > Test::altNames;
78 bool Test::runOnce = false;
79
113 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
114
115 Test::Test()
116 {
117 if (runOnce)
118 return;
119 runOnce = true;
120 connection_.setUp();
121 init();

--- 45 unchanged lines hidden (view full) ---

167 {
168 ne_ssl_certificate* cert = ne_ssl_cert_read(filename);
169 char* certExportB64 = ne_ssl_cert_export(cert);
170 rtl::OString certB64( certExportB64 );
171 return certB64;
172 }
173
174
80
81 Test::Test()
82 {
83 if (runOnce)
84 return;
85 runOnce = true;
86 connection_.setUp();
87 init();

--- 45 unchanged lines hidden (view full) ---

133 {
134 ne_ssl_certificate* cert = ne_ssl_cert_read(filename);
135 char* certExportB64 = ne_ssl_cert_export(cert);
136 rtl::OString certB64( certExportB64 );
137 return certB64;
138 }
139
140
175 void Test::setUp() {
141 void Test::SetUp() {
176 }
177
142 }
143
178 void Test::tearDown() {
144 void Test::TearDown() {
179 }
180
145 }
146
181 void Test::test_Others() {
182 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
147 TEST_F(Test, test_Others) {
148 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
183 for(int n = 1; n < altNames.getLength(); n++)
184 {
185 if (altNames[n].Type == security::ExtAltNameType_OTHER_NAME)
186 {
187 ::com::sun::star::beans::NamedValue otherNameProp;
188 if (altNames[n].Value >>= otherNameProp)
189 {
149 for(int n = 1; n < altNames.getLength(); n++)
150 {
151 if (altNames[n].Type == security::ExtAltNameType_OTHER_NAME)
152 {
153 ::com::sun::star::beans::NamedValue otherNameProp;
154 if (altNames[n].Value >>= otherNameProp)
155 {
190 CPPUNIT_ASSERT_EQUAL( rtl::OUString::createFromAscii("1.2.3.4"), otherNameProp.Name);
156 ASSERT_EQ( rtl::OUString::createFromAscii("1.2.3.4"), otherNameProp.Name);
191 uno::Sequence< sal_Int8 > ipAddress;
192 otherNameProp.Value >>= ipAddress;
157 uno::Sequence< sal_Int8 > ipAddress;
158 otherNameProp.Value >>= ipAddress;
193 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( ipAddress.getLength() > 0 ) );
159 ASSERT_NO_THROW( ASSERT_TRUE( ipAddress.getLength() > 0 ) );
194 }
195 }
196 }
197 }
198
160 }
161 }
162 }
163 }
164
199 void Test::test_RFC822() {
200 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
165 TEST_F(Test, test_RFC822) {
166 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
201 for(int n = 1; n < altNames.getLength(); n++)
202 {
203 if (altNames[n].Type == security::ExtAltNameType_RFC822_NAME)
204 {
205 rtl::OUString value;
206 altNames[n].Value >>= value;
167 for(int n = 1; n < altNames.getLength(); n++)
168 {
169 if (altNames[n].Type == security::ExtAltNameType_RFC822_NAME)
170 {
171 rtl::OUString value;
172 altNames[n].Value >>= value;
207 CPPUNIT_ASSERT_EQUAL( rtl::OUString::createFromAscii("my@other.address"), value);
173 ASSERT_EQ( rtl::OUString::createFromAscii("my@other.address"), value );
208 }
209 }
210 }
211
174 }
175 }
176 }
177
212 void Test::test_DNS() {
213 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
178 TEST_F(Test, test_DNS) {
179 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
214 for(int n = 1; n < altNames.getLength(); n++)
215 {
216 if (altNames[n].Type == security::ExtAltNameType_DNS_NAME)
217 {
218 rtl::OUString value;
219 altNames[n].Value >>= value;
180 for(int n = 1; n < altNames.getLength(); n++)
181 {
182 if (altNames[n].Type == security::ExtAltNameType_DNS_NAME)
183 {
184 rtl::OUString value;
185 altNames[n].Value >>= value;
220 CPPUNIT_ASSERT_EQUAL( rtl::OUString::createFromAscii("alt.openoffice.org"), value);
186 ASSERT_EQ( rtl::OUString::createFromAscii("alt.openoffice.org"), value);
221 }
222 }
223 }
224
187 }
188 }
189 }
190
225 void Test::test_Direcory() {
191 TEST_F(Test, test_Direcory) {
226 // Not implemented
227 }
228
192 // Not implemented
193 }
194
229 void Test::test_URI() {
230 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
195 TEST_F(Test, test_URI) {
196 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
231 for(int n = 1; n < altNames.getLength(); n++)
232 {
233 if (altNames[n].Type == security::ExtAltNameType_URL)
234 {
235 rtl::OUString value;
236 altNames[n].Value >>= value;
197 for(int n = 1; n < altNames.getLength(); n++)
198 {
199 if (altNames[n].Type == security::ExtAltNameType_URL)
200 {
201 rtl::OUString value;
202 altNames[n].Value >>= value;
237 CPPUNIT_ASSERT_EQUAL( rtl::OUString::createFromAscii("http://my.url.here/"), value);
203 ASSERT_EQ( rtl::OUString::createFromAscii("http://my.url.here/"), value);
238 }
239 }
240 }
241
204 }
205 }
206 }
207
242 void Test::test_IP() {
243 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
208 TEST_F(Test, test_IP) {
209 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
244 for(int n = 1; n < altNames.getLength(); n++)
245 {
246 if (altNames[n].Type == security::ExtAltNameType_IP_ADDRESS)
247 {
248 uno::Sequence< sal_Int8 > ipAddress;
249 altNames[n].Value >>= ipAddress;
210 for(int n = 1; n < altNames.getLength(); n++)
211 {
212 if (altNames[n].Type == security::ExtAltNameType_IP_ADDRESS)
213 {
214 uno::Sequence< sal_Int8 > ipAddress;
215 altNames[n].Value >>= ipAddress;
250 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( ipAddress.getLength() > 0 ) );
216 ASSERT_NO_THROW( ASSERT_TRUE( ipAddress.getLength() > 0 ) );
251 }
252 }
253
254 }
255
217 }
218 }
219
220 }
221
256 void Test::test_RID() {
257 CPPUNIT_ASSERT_ASSERTION_PASS( CPPUNIT_ASSERT( altNames.getLength() > 0 ) );
222 TEST_F(Test, test_RID) {
223 ASSERT_NO_THROW( ASSERT_TRUE( altNames.getLength() > 0 ) );
258 for(int n = 1; n < altNames.getLength(); n++)
259 {
260 if (altNames[n].Type == security::ExtAltNameType_REGISTERED_ID)
261 {
262 rtl::OUString value;
263 altNames[n].Value >>= value;
224 for(int n = 1; n < altNames.getLength(); n++)
225 {
226 if (altNames[n].Type == security::ExtAltNameType_REGISTERED_ID)
227 {
228 rtl::OUString value;
229 altNames[n].Value >>= value;
264 CPPUNIT_ASSERT( rtl::OUString::createFromAscii("1.2.3.4").equals(value));
230 ASSERT_TRUE( rtl::OUString::createFromAscii("1.2.3.4").equals(value));
265 }
266 }
267 }
268
231 }
232 }
233 }
234
269 void Test::test_EDI() {
235 TEST_F(Test, test_EDI) {
270 // Not implemented
271 }
272
236 // Not implemented
237 }
238
273 void Test::test_X400() {
239 TEST_F(Test, test_X400) {
274 // Not implemented
275 }
276}
240 // Not implemented
241 }
242}
277CPPUNIT_PLUGIN_IMPLEMENT();