LibreOffice Module comphelper (master)  1
docpasswordhelper.cxx
Go to the documentation of this file.
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 #include <config_gpgme.h>
21 
22 #include <algorithm>
23 
26 #include <comphelper/hash.hxx>
27 #include <comphelper/base64.hxx>
28 #include <comphelper/sequence.hxx>
29 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/task/XInteractionHandler.hpp>
32 
33 #include <osl/diagnose.h>
34 #include <sal/log.hxx>
35 #include <rtl/digest.h>
36 #include <rtl/random.h>
37 #include <string.h>
38 
39 #if HAVE_FEATURE_GPGME
40 # include <context.h>
41 # include <data.h>
42 # include <decryptionresult.h>
43 #endif
44 
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Exception;
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::task::PasswordRequestMode;
49 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_ENTER;
50 using ::com::sun::star::task::PasswordRequestMode_PASSWORD_REENTER;
51 using ::com::sun::star::task::XInteractionHandler;
52 using ::com::sun::star::task::XInteractionRequest;
53 
54 using namespace ::com::sun::star;
55 
56 namespace comphelper {
57 
58 
59 static uno::Sequence< sal_Int8 > GeneratePBKDF2Hash( const OUString& aPassword, const uno::Sequence< sal_Int8 >& aSalt, sal_Int32 nCount, sal_Int32 nHashLength )
60 {
61  uno::Sequence< sal_Int8 > aResult;
62 
63  if ( !aPassword.isEmpty() && aSalt.hasElements() && nCount && nHashLength )
64  {
65  OString aBytePass = OUStringToOString( aPassword, RTL_TEXTENCODING_UTF8 );
66  // FIXME this is subject to the SHA1-bug tdf#114939 - see also
67  // RequestPassword() in filedlghelper.cxx
68  aResult.realloc( 16 );
69  rtl_digest_PBKDF2( reinterpret_cast < sal_uInt8 * > ( aResult.getArray() ),
70  aResult.getLength(),
71  reinterpret_cast < const sal_uInt8 * > ( aBytePass.getStr() ),
72  aBytePass.getLength(),
73  reinterpret_cast < const sal_uInt8 * > ( aSalt.getConstArray() ),
74  aSalt.getLength(),
75  nCount );
76  }
77 
78  return aResult;
79 }
80 
81 
83 {
84 }
85 
86 
87 uno::Sequence< beans::PropertyValue > DocPasswordHelper::GenerateNewModifyPasswordInfo( const OUString& aPassword )
88 {
89  uno::Sequence< beans::PropertyValue > aResult;
90 
91  uno::Sequence< sal_Int8 > aSalt = GenerateRandomByteSequence( 16 );
92  sal_Int32 const nPBKDF2IterationCount = 100000;
93 
94  uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash(aPassword, aSalt, nPBKDF2IterationCount, 16);
95  if ( aNewHash.hasElements() )
96  {
97  aResult.realloc( 4 );
98  aResult[0].Name = "algorithm-name";
99  aResult[0].Value <<= OUString( "PBKDF2" );
100  aResult[1].Name = "salt";
101  aResult[1].Value <<= aSalt;
102  aResult[2].Name = "iteration-count";
103  aResult[2].Value <<= nPBKDF2IterationCount;
104  aResult[3].Name = "hash";
105  aResult[3].Value <<= aNewHash;
106  }
107 
108  return aResult;
109 }
110 
111 
112 bool DocPasswordHelper::IsModifyPasswordCorrect( const OUString& aPassword, const uno::Sequence< beans::PropertyValue >& aInfo )
113 {
114  bool bResult = false;
115  if ( !aPassword.isEmpty() && aInfo.hasElements() )
116  {
117  OUString sAlgorithm;
118  uno::Sequence< sal_Int8 > aSalt;
119  uno::Sequence< sal_Int8 > aHash;
120  sal_Int32 nCount = 0;
121 
122  for ( sal_Int32 nInd = 0; nInd < aInfo.getLength(); nInd++ )
123  {
124  if ( aInfo[nInd].Name == "algorithm-name" )
125  aInfo[nInd].Value >>= sAlgorithm;
126  else if ( aInfo[nInd].Name == "salt" )
127  aInfo[nInd].Value >>= aSalt;
128  else if ( aInfo[nInd].Name == "iteration-count" )
129  aInfo[nInd].Value >>= nCount;
130  else if ( aInfo[nInd].Name == "hash" )
131  aInfo[nInd].Value >>= aHash;
132  }
133 
134  if ( sAlgorithm == "PBKDF2" && aSalt.hasElements() && nCount > 0 && aHash.hasElements() )
135  {
136  uno::Sequence< sal_Int8 > aNewHash = GeneratePBKDF2Hash( aPassword, aSalt, nCount, aHash.getLength() );
137  for ( sal_Int32 nInd = 0; nInd < aNewHash.getLength() && nInd < aHash.getLength() && aNewHash[nInd] == aHash[nInd]; nInd ++ )
138  {
139  if ( nInd == aNewHash.getLength() - 1 && nInd == aHash.getLength() - 1 )
140  bResult = true;
141  }
142  }
143  }
144 
145  return bResult;
146 }
147 
148 
150  const OUString& aUString )
151 {
152  static const sal_uInt16 pInitialCode[] = {
153  0xE1F0, // 1
154  0x1D0F, // 2
155  0xCC9C, // 3
156  0x84C0, // 4
157  0x110C, // 5
158  0x0E10, // 6
159  0xF1CE, // 7
160  0x313E, // 8
161  0x1872, // 9
162  0xE139, // 10
163  0xD40F, // 11
164  0x84F9, // 12
165  0x280C, // 13
166  0xA96A, // 14
167  0x4EC3 // 15
168  };
169 
170  static const sal_uInt16 pEncryptionMatrix[15][7] = {
171  { 0xAEFC, 0x4DD9, 0x9BB2, 0x2745, 0x4E8A, 0x9D14, 0x2A09}, // last-14
172  { 0x7B61, 0xF6C2, 0xFDA5, 0xEB6B, 0xC6F7, 0x9DCF, 0x2BBF}, // last-13
173  { 0x4563, 0x8AC6, 0x05AD, 0x0B5A, 0x16B4, 0x2D68, 0x5AD0}, // last-12
174  { 0x0375, 0x06EA, 0x0DD4, 0x1BA8, 0x3750, 0x6EA0, 0xDD40}, // last-11
175  { 0xD849, 0xA0B3, 0x5147, 0xA28E, 0x553D, 0xAA7A, 0x44D5}, // last-10
176  { 0x6F45, 0xDE8A, 0xAD35, 0x4A4B, 0x9496, 0x390D, 0x721A}, // last-9
177  { 0xEB23, 0xC667, 0x9CEF, 0x29FF, 0x53FE, 0xA7FC, 0x5FD9}, // last-8
178  { 0x47D3, 0x8FA6, 0x8FA6, 0x1EDA, 0x3DB4, 0x7B68, 0xF6D0}, // last-7
179  { 0xB861, 0x60E3, 0xC1C6, 0x93AD, 0x377B, 0x6EF6, 0xDDEC}, // last-6
180  { 0x45A0, 0x8B40, 0x06A1, 0x0D42, 0x1A84, 0x3508, 0x6A10}, // last-5
181  { 0xAA51, 0x4483, 0x8906, 0x022D, 0x045A, 0x08B4, 0x1168}, // last-4
182  { 0x76B4, 0xED68, 0xCAF1, 0x85C3, 0x1BA7, 0x374E, 0x6E9C}, // last-3
183  { 0x3730, 0x6E60, 0xDCC0, 0xA9A1, 0x4363, 0x86C6, 0x1DAD}, // last-2
184  { 0x3331, 0x6662, 0xCCC4, 0x89A9, 0x0373, 0x06E6, 0x0DCC}, // last-1
185  { 0x1021, 0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48C4} // last
186  };
187 
188  sal_uInt32 nResult = 0;
189  sal_uInt32 nLen = aUString.getLength();
190 
191  if ( nLen )
192  {
193  if ( nLen > 15 )
194  nLen = 15;
195 
196  sal_uInt16 nHighResult = pInitialCode[nLen - 1];
197  sal_uInt16 nLowResult = 0;
198 
199  for ( sal_uInt32 nInd = 0; nInd < nLen; nInd++ )
200  {
201  // NO Encoding during conversion!
202  // The specification says that the low byte should be used in case it is not NULL
203  char nHighChar = static_cast<char>( aUString[nInd] >> 8 );
204  char nLowChar = static_cast<char>( aUString[nInd] & 0xFF );
205  char nChar = nLowChar ? nLowChar : nHighChar;
206 
207  for ( int nMatrixInd = 0; nMatrixInd < 7; ++nMatrixInd )
208  {
209  if ( ( nChar & ( 1 << nMatrixInd ) ) != 0 )
210  nHighResult = nHighResult ^ pEncryptionMatrix[15 - nLen + nInd][nMatrixInd];
211  }
212 
213  nLowResult = ( ( ( nLowResult >> 14 ) & 0x0001 ) | ( ( nLowResult << 1 ) & 0x7FFF ) ) ^ nChar;
214  }
215 
216  nLowResult = static_cast<sal_uInt16>( ( ( ( nLowResult >> 14 ) & 0x001 ) | ( ( nLowResult << 1 ) & 0x7FF ) ) ^ nLen ^ 0xCE4B );
217 
218  nResult = ( nHighResult << 16 ) | nLowResult;
219  }
220 
221  return nResult;
222 }
223 
224 
226  const OUString& aUString,
227  rtl_TextEncoding nEnc )
228 {
229  sal_uInt16 nResult = 0;
230 
231  OString aString = OUStringToOString( aUString, nEnc );
232 
233  if ( !aString.isEmpty() && aString.getLength() <= SAL_MAX_UINT16 )
234  {
235  for ( sal_Int32 nInd = aString.getLength() - 1; nInd >= 0; nInd-- )
236  {
237  nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF );
238  nResult ^= aString[nInd];
239  }
240 
241  nResult = ( ( nResult >> 14 ) & 0x01 ) | ( ( nResult << 1 ) & 0x7FFF );
242  nResult ^= ( 0x8000 | ( 'N' << 8 ) | 'K' );
243  nResult ^= aString.getLength();
244  }
245 
246  return nResult;
247 }
248 
249 
251  const OUString& aUString )
252 {
253  sal_uInt16 nHash = GetXLHashAsUINT16( aUString );
254  return {sal_Int8(nHash >> 8), sal_Int8(nHash & 0xFF)};
255 }
256 
257 
258 std::vector<unsigned char> DocPasswordHelper::GetOoxHashAsVector(
259  const OUString& rPassword,
260  const std::vector<unsigned char>& rSaltValue,
261  sal_uInt32 nSpinCount,
262  comphelper::Hash::IterCount eIterCount,
263  const OUString& rAlgorithmName)
264 {
266  if (rAlgorithmName == "SHA-512" || rAlgorithmName == "SHA512")
268  else if (rAlgorithmName == "SHA-256" || rAlgorithmName == "SHA256")
270  else if (rAlgorithmName == "SHA-1" || rAlgorithmName == "SHA1") // "SHA1" might be in the wild
272  else if (rAlgorithmName == "MD5")
274  else
275  return std::vector<unsigned char>();
276 
277  return comphelper::Hash::calculateHash( rPassword, rSaltValue, nSpinCount, eIterCount, eType);
278 }
279 
280 
281 css::uno::Sequence<sal_Int8> DocPasswordHelper::GetOoxHashAsSequence(
282  const OUString& rPassword,
283  const OUString& rSaltValue,
284  sal_uInt32 nSpinCount,
285  comphelper::Hash::IterCount eIterCount,
286  const OUString& rAlgorithmName)
287 {
288  std::vector<unsigned char> aSaltVec;
289  if (!rSaltValue.isEmpty())
290  {
291  css::uno::Sequence<sal_Int8> aSaltSeq;
292  comphelper::Base64::decode( aSaltSeq, rSaltValue);
293  aSaltVec = comphelper::sequenceToContainer<std::vector<unsigned char>>( aSaltSeq);
294  }
295 
296  std::vector<unsigned char> hash( GetOoxHashAsVector( rPassword, aSaltVec, nSpinCount, eIterCount, rAlgorithmName));
297 
298  return comphelper::containerToSequence<sal_Int8>( hash);
299 }
300 
302  const OUString& rPassword,
303  const OUString& rSaltValue,
304  sal_uInt32 nSpinCount,
305  comphelper::Hash::IterCount eIterCount,
306  const OUString& rAlgorithmName)
307 {
308  css::uno::Sequence<sal_Int8> aSeq( GetOoxHashAsSequence( rPassword, rSaltValue, nSpinCount,
309  eIterCount, rAlgorithmName));
310 
311  OUStringBuffer aBuf((aSeq.getLength()+2)/3*4);
312  comphelper::Base64::encode( aBuf, aSeq);
313  return aBuf.makeStringAndClear();
314 }
315 
316 
317 /*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateRandomByteSequence( sal_Int32 nLength )
318 {
319  uno::Sequence< sal_Int8 > aResult( nLength );
320 
321  rtlRandomPool aRandomPool = rtl_random_createPool ();
322  rtl_random_getBytes ( aRandomPool, aResult.getArray(), nLength );
323  rtl_random_destroyPool ( aRandomPool );
324 
325  return aResult;
326 }
327 
328 
329 /*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const OUString& aPassword, const uno::Sequence< sal_Int8 >& aDocId )
330 {
331  uno::Sequence< sal_Int8 > aResultKey;
332  if ( !aPassword.isEmpty() && aDocId.getLength() == 16 )
333  {
334  sal_uInt16 pPassData[16] = {};
335 
336  sal_Int32 nPassLen = std::min< sal_Int32 >( aPassword.getLength(), 15 );
337  memcpy( pPassData, aPassword.getStr(), nPassLen * sizeof(pPassData[0]) );
338 
339  aResultKey = GenerateStd97Key( pPassData, aDocId );
340  }
341 
342  return aResultKey;
343 }
344 
345 
346 /*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const sal_uInt16 pPassData[16], const uno::Sequence< sal_Int8 >& aDocId )
347 {
348  uno::Sequence< sal_Int8 > aResultKey;
349 
350  if ( aDocId.getLength() == 16 )
351  aResultKey = GenerateStd97Key(pPassData, reinterpret_cast<const sal_uInt8*>(aDocId.getConstArray()));
352 
353  return aResultKey;
354 }
355 
356 
357 /*static*/ uno::Sequence< sal_Int8 > DocPasswordHelper::GenerateStd97Key( const sal_uInt16 pPassData[16], const sal_uInt8 pDocId[16] )
358 {
359  uno::Sequence< sal_Int8 > aResultKey;
360  if ( pPassData[0] )
361  {
362  sal_uInt8 pKeyData[64] = {};
363 
364  sal_Int32 nInd = 0;
365 
366  // Fill PassData into KeyData.
367  for ( nInd = 0; nInd < 16 && pPassData[nInd]; nInd++)
368  {
369  pKeyData[2*nInd] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 0) & 0xff );
370  pKeyData[2*nInd + 1] = sal::static_int_cast< sal_uInt8 >( (pPassData[nInd] >> 8) & 0xff );
371  }
372 
373  pKeyData[2*nInd] = 0x80;
374  pKeyData[56] = sal::static_int_cast< sal_uInt8 >( nInd << 4 );
375 
376  // Fill raw digest of KeyData into KeyData.
377  rtlDigest hDigest = rtl_digest_create ( rtl_Digest_AlgorithmMD5 );
378  (void)rtl_digest_updateMD5 (
379  hDigest, pKeyData, sizeof(pKeyData));
380  (void)rtl_digest_rawMD5 (
381  hDigest, pKeyData, RTL_DIGEST_LENGTH_MD5);
382 
383  // Update digest with KeyData and Unique.
384  for ( nInd = 0; nInd < 16; nInd++ )
385  {
386  rtl_digest_updateMD5( hDigest, pKeyData, 5 );
387  rtl_digest_updateMD5( hDigest, pDocId, 16 );
388  }
389 
390  // Update digest with padding.
391  pKeyData[16] = 0x80;
392  memset( pKeyData + 17, 0, sizeof(pKeyData) - 17 );
393  pKeyData[56] = 0x80;
394  pKeyData[57] = 0x0a;
395 
396  rtl_digest_updateMD5( hDigest, &(pKeyData[16]), sizeof(pKeyData) - 16 );
397 
398  // Fill raw digest of above updates
399  aResultKey.realloc( RTL_DIGEST_LENGTH_MD5 );
400  rtl_digest_rawMD5 ( hDigest, reinterpret_cast<sal_uInt8*>(aResultKey.getArray()), aResultKey.getLength() );
401 
402  // Erase KeyData array and leave.
403  rtl_secureZeroMemory (pKeyData, sizeof(pKeyData));
404 
405  rtl_digest_destroy(hDigest);
406  }
407 
408  return aResultKey;
409 }
410 
411 
412 /*static*/ css::uno::Sequence< css::beans::NamedValue > DocPasswordHelper::requestAndVerifyDocPassword(
413  IDocPasswordVerifier& rVerifier,
414  const css::uno::Sequence< css::beans::NamedValue >& rMediaEncData,
415  const OUString& rMediaPassword,
416  const Reference< XInteractionHandler >& rxInteractHandler,
417  const OUString& rDocumentUrl,
418  DocPasswordRequestType eRequestType,
419  const std::vector< OUString >* pDefaultPasswords,
420  bool* pbIsDefaultPassword )
421 {
422  css::uno::Sequence< css::beans::NamedValue > aEncData;
424 
425  // first, try provided default passwords
426  if( pbIsDefaultPassword )
427  *pbIsDefaultPassword = false;
428  if( pDefaultPasswords )
429  {
430  for( const auto& rPassword : *pDefaultPasswords )
431  {
432  OSL_ENSURE( !rPassword.isEmpty(), "DocPasswordHelper::requestAndVerifyDocPassword - unexpected empty default password" );
433  if( !rPassword.isEmpty() )
434  {
435  eResult = rVerifier.verifyPassword( rPassword, aEncData );
436  if( pbIsDefaultPassword )
437  *pbIsDefaultPassword = eResult == DocPasswordVerifierResult::OK;
439  break;
440  }
441  }
442  }
443 
444  // try media encryption data (skip, if result is OK or ABORT)
446  {
447  if( rMediaEncData.hasElements() )
448  {
449  eResult = rVerifier.verifyEncryptionData( rMediaEncData );
450  if( eResult == DocPasswordVerifierResult::OK )
451  aEncData = rMediaEncData;
452  }
453  }
454 
455  // try media password (skip, if result is OK or ABORT)
457  {
458  if( !rMediaPassword.isEmpty() )
459  eResult = rVerifier.verifyPassword( rMediaPassword, aEncData );
460  }
461 
462  // request a password (skip, if result is OK or ABORT)
463  if( (eResult == DocPasswordVerifierResult::WrongPassword) && rxInteractHandler.is() ) try
464  {
465  PasswordRequestMode eRequestMode = PasswordRequestMode_PASSWORD_ENTER;
466  while( eResult == DocPasswordVerifierResult::WrongPassword )
467  {
468  DocPasswordRequest* pRequest = new DocPasswordRequest( eRequestType, eRequestMode, rDocumentUrl );
469  Reference< XInteractionRequest > xRequest( pRequest );
470  rxInteractHandler->handle( xRequest );
471  if( pRequest->isPassword() )
472  {
473  if( !pRequest->getPassword().isEmpty() )
474  eResult = rVerifier.verifyPassword( pRequest->getPassword(), aEncData );
475  }
476  else
477  {
479  }
480  eRequestMode = PasswordRequestMode_PASSWORD_REENTER;
481  }
482  }
483  catch( Exception& )
484  {
485  }
486 
487  return (eResult == DocPasswordVerifierResult::OK) ? aEncData : uno::Sequence< beans::NamedValue >();
488 }
489 
490 /*static*/ uno::Sequence< css::beans::NamedValue >
492  const uno::Sequence< uno::Sequence< beans::NamedValue > >& rGpgProperties )
493 {
494 #if HAVE_FEATURE_GPGME
495  if ( !rGpgProperties.hasElements() )
496  return uno::Sequence< beans::NamedValue >();
497 
498  uno::Sequence< beans::NamedValue > aEncryptionData(1);
499  std::unique_ptr<GpgME::Context> ctx;
500  GpgME::initializeLibrary();
501  GpgME::Error err = GpgME::checkEngine(GpgME::OpenPGP);
502  if (err)
503  throw uno::RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
504 
505  ctx.reset( GpgME::Context::createForProtocol(GpgME::OpenPGP) );
506  if (ctx == nullptr)
507  throw uno::RuntimeException("The GpgME library failed to initialize for the OpenPGP protocol.");
508  ctx->setArmor(false);
509 
510  const uno::Sequence < beans::NamedValue > *pSequence = rGpgProperties.getConstArray();
511  const sal_Int32 nLength = rGpgProperties.getLength();
512  for ( sal_Int32 i = 0; i < nLength ; i++, pSequence++ )
513  {
514  const beans::NamedValue *pValues = pSequence->getConstArray();
515  if ( pSequence->getLength() == 3 )
516  {
517  // take CipherValue and try to decrypt that - stop after
518  // the first successful decryption
519 
520  // ctx is setup now, let's decrypt the lot!
521  uno::Sequence < sal_Int8 > aVector;
522  pValues[2].Value >>= aVector;
523 
524  GpgME::Data cipher(
525  reinterpret_cast<const char*>(aVector.getConstArray()),
526  size_t(aVector.getLength()), false);
527  GpgME::Data plain;
528 
529  GpgME::DecryptionResult crypt_res = ctx->decrypt(
530  cipher, plain);
531 
532  // NO_SECKEY -> skip
533  // BAD_PASSPHRASE -> retry?
534 
535  off_t result = plain.seek(0,SEEK_SET);
536  (void) result;
537  assert(result == 0);
538  int len=0, curr=0; char buf;
539  while( (curr=plain.read(&buf, 1)) )
540  len += curr;
541 
542  if(crypt_res.error() || !len)
543  continue; // can't use this key, take next one
544 
545  uno::Sequence < sal_Int8 > aKeyValue(len);
546  result = plain.seek(0,SEEK_SET);
547  assert(result == 0);
548  if( plain.read(aKeyValue.getArray(), len) != len )
549  throw uno::RuntimeException("The GpgME library failed to read the encrypted value.");
550 
551  SAL_INFO("comphelper.crypto", "Extracted gpg session key of length: " << len);
552 
553  aEncryptionData[0].Name = PACKAGE_ENCRYPTIONDATA_SHA256UTF8;
554  aEncryptionData[0].Value <<= aKeyValue;
555  break;
556  }
557  }
558 
559  if ( aEncryptionData[0].Value.hasValue() )
560  {
561  uno::Sequence< beans::NamedValue > aContainer(2);
562  aContainer[0].Name = "GpgInfos";
563  aContainer[0].Value <<= rGpgProperties;
564  aContainer[1].Name = "EncryptionKey";
565  aContainer[1].Value <<= aEncryptionData;
566 
567  return aContainer;
568  }
569 #else
570  (void)rGpgProperties;
571 #endif
572  return uno::Sequence< beans::NamedValue >();
573 }
574 
575 } // namespace comphelper
576 
577 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
tuple ctx
Implements the task.XInteractionRequest interface for requesting a password string for a document...
signed char sal_Int8
virtual DocPasswordVerifierResult verifyEncryptionData(const css::uno::Sequence< css::beans::NamedValue > &o_rEncryptionData)=0
Will be called every time an encryption data needs to be verified.
static std::vector< unsigned char > calculateHash(const unsigned char *pInput, size_t length, HashType eType)
Definition: hash.cxx:148
aBuf
OUString Name
Value
static css::uno::Sequence< sal_Int8 > GetOoxHashAsSequence(const OUString &rPassword, const OUString &rSaltValue, sal_uInt32 nSpinCount, comphelper::Hash::IterCount eIterCount, const OUString &rAlgorithmName)
Convenience function to calculate a salted hash with iterations as specified in https://msdn.microsoft.com/en-us/library/dd920692 for the OOXML sheetProtection and fileSharing elements, or https://msdn.microsoft.com/en-us/library/dd924776 and https://msdn.microsoft.com/en-us/library/dd925430 for Standard and Agile Encryption.
#define SAL_MAX_UINT16
static void encode(OUStringBuffer &aStrBuffer, const css::uno::Sequence< sal_Int8 > &aPass)
encodes the given byte sequence into Base64
static OUString GetOoxHashAsBase64(const OUString &rPassword, const OUString &rSaltValue, sal_uInt32 nSpinCount, comphelper::Hash::IterCount eIterCount, const OUString &rAlgorithmName)
Convenience function to calculate a salted hash with iterations as specified in https://msdn.microsoft.com/en-us/library/dd920692 for the OOXML sheetProtection and fileSharing elements, or https://msdn.microsoft.com/en-us/library/dd924776 and https://msdn.microsoft.com/en-us/library/dd925430 for Standard and Agile Encryption.
static bool IsModifyPasswordCorrect(const OUString &aPassword, const css::uno::Sequence< css::beans::PropertyValue > &aInfo)
This helper function allows to check whether the "Password to modify" provided by user is the correct...
err
static sal_uInt16 GetXLHashAsUINT16(const OUString &aString, rtl_TextEncoding nEnc=RTL_TEXTENCODING_UTF8)
This helper function generates the hash code based on the algorithm specified by MS for "Password to ...
static css::uno::Sequence< css::beans::NamedValue > decryptGpgSession(const css::uno::Sequence< css::uno::Sequence< css::beans::NamedValue > > &rGpgProperties)
static void decode(css::uno::Sequence< sal_Int8 > &aPass, const OUString &sBuffer)
Definition: base64.cxx:139
MetadataImporterPluginType * result
int i
static css::uno::Sequence< css::beans::PropertyValue > GenerateNewModifyPasswordInfo(const OUString &aPassword)
This helper function generates the information related to "Password to modify" provided by user...
static css::uno::Sequence< sal_Int8 > GenerateStd97Key(const OUString &aPassword, const css::uno::Sequence< sal_Int8 > &aDocId)
This helper function generates a byte sequence representing the key digest value used by MSCodec_Std9...
DocumentType const eType
DocPasswordRequestType
Selects which UNO document password request type to use.
OString OUStringToOString(const OUString &str, ConnectionSettings const *settings)
static css::uno::Sequence< sal_Int8 > GenerateRandomByteSequence(sal_Int32 nLength)
This helper function generates a random sequence of bytes of requested length.
void * rtlRandomPool
unsigned char sal_uInt8
#define PACKAGE_ENCRYPTIONDATA_SHA256UTF8
Base class for a password verifier used by the DocPasswordHelper class below.
static css::uno::Sequence< css::beans::NamedValue > requestAndVerifyDocPassword(IDocPasswordVerifier &rVerifier, const css::uno::Sequence< css::beans::NamedValue > &rMediaEncData, const OUString &rMediaPassword, const css::uno::Reference< css::task::XInteractionHandler > &rxInteractHandler, const OUString &rDocumentUrl, DocPasswordRequestType eRequestType, const ::std::vector< OUString > *pDefaultPasswords=nullptr, bool *pbIsDefaultPassword=nullptr)
This helper function tries to request and verify a password to load a protected document.
#define SAL_INFO(area, stream)
static sal_uInt32 GetWordHashAsUINT32(const OUString &aString)
This helper function generates the hash code based on the algorithm specified by MS for "Password to ...
static std::vector< unsigned char > GetOoxHashAsVector(const OUString &rPassword, const std::vector< unsigned char > &rSaltValue, sal_uInt32 nSpinCount, comphelper::Hash::IterCount eIterCount, const OUString &rAlgorithmName)
Convenience function to calculate a salted hash with iterations as specified in https://msdn.microsoft.com/en-us/library/dd920692 for the OOXML sheetProtection and fileSharing elements, or https://msdn.microsoft.com/en-us/library/dd924776 and https://msdn.microsoft.com/en-us/library/dd925430 for Standard and Agile Encryption.
sal_Int32 const nLength
virtual DocPasswordVerifierResult verifyPassword(const OUString &rPassword, css::uno::Sequence< css::beans::NamedValue > &o_rEncryptionData)=0
Will be called every time a password needs to be verified.
static css::uno::Sequence< sal_Int8 > GetXLHashAsSequence(const OUString &aString)
This helper function generates the hash code based on the algorithm specified by MS for "Password to ...
static uno::Sequence< sal_Int8 > GeneratePBKDF2Hash(const OUString &aPassword, const uno::Sequence< sal_Int8 > &aSalt, sal_Int32 nCount, sal_Int32 nHashLength)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo