Skip to content

Commit 51a8ff6

Browse files
committed
core: Fix #641: Use cc/crypto module as cryptographic provider
1 parent 75cdbe4 commit 51a8ff6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1929
-3602
lines changed

cc7

Submodule cc7 updated 104 files

include/PowerAuth/ECIES.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <PowerAuth/PublicTypes.h>
20+
#include <cc7/crypto/KeyPair.h>
2021

2122
/*
2223
The ECIES.h header file contains a set of interfaces prepared for ECIES data
@@ -207,11 +208,11 @@ namespace powerAuth
207208
/// Creates a new instance of ECIESEnvelopeKey from EC |publiKey| and optional |shared_info1|.
208209
/// For optional |shared_info1| you can provide an empty range, if you have no such information available.
209210
/// The method also stores a newly created ephemeral public key to the |out_ephemeralKey| reference.
210-
static ECIESEnvelopeKey fromPublicKey(const cc7::ByteRange & public_key, const cc7::ByteRange & shared_info1, cc7::ByteArray & out_ephemeral_key);
211+
static ECIESEnvelopeKey fromPublicKey(const cc7::crypto::PublicKeyPtr & public_key, const cc7::ByteRange & shared_info1, cc7::ByteArray & out_ephemeral_key);
211212

212213
/// Creates a new instance of ECIESEnvelopeKey from EC |privateKey|, |ephemeralKey| key-pair and optional |shared_info1|.
213214
/// For optional |shared_info1| you can provide an empty range, if you have no such information available.
214-
static ECIESEnvelopeKey fromPrivateKey(const cc7::ByteArray & private_key, const cc7::ByteRange & ephemeral_key, const cc7::ByteRange & shared_info1);
215+
static ECIESEnvelopeKey fromPrivateKey(const cc7::crypto::PrivateKeyPtr & private_key, const cc7::ByteRange & ephemeral_key, const cc7::ByteRange & shared_info1);
215216

216217
public:
217218

@@ -247,7 +248,7 @@ namespace powerAuth
247248
/// Constructs an ecnryptor with server's |public_key| and optional |shared_info1| and |shared_info2|.
248249
/// For both optional parameters you can provide an empty range, if you have no such information available.
249250
/// The constructed instance can be used for both encryption and decryption tasks.
250-
ECIESEncryptor(const cc7::ByteRange & public_key, const cc7::ByteRange & shared_info1, const cc7::ByteRange & shared_info2);
251+
ECIESEncryptor(const cc7::crypto::PublicKeyPtr & public_key, const cc7::ByteRange & shared_info1, const cc7::ByteRange & shared_info2);
251252

252253
/// Constructs an encryptor with previously calculated |envelope_key| and optional |shared_info2|.
253254
/// For optional |shared_info2| you can provide an empty range, if you have no such information available.
@@ -256,7 +257,7 @@ namespace powerAuth
256257

257258

258259
/// Returns a reference to public key.
259-
const cc7::ByteArray & publicKey() const;
260+
const cc7::crypto::PublicKeyPtr & publicKey() const;
260261

261262
/// Returns a reference to envelope key.
262263
const ECIESEnvelopeKey & envelopeKey() const;
@@ -305,7 +306,7 @@ namespace powerAuth
305306
private:
306307

307308
/// A data for public key.
308-
cc7::ByteArray _public_key;
309+
cc7::crypto::PublicKeyPtr _public_key;
309310
/// Content of shared info1 optional parameter.
310311
cc7::ByteArray _shared_info1;
311312
/// Content of shared info2 optional parameter.
@@ -326,14 +327,14 @@ namespace powerAuth
326327

327328
/// Constructs a decryptor with a server's |private_key| and optional |shared_info1| and |shared_info2|.
328329
/// The constructed instance can be used for both decryption & encryption tasks.
329-
ECIESDecryptor(const cc7::ByteArray & private_key, const cc7::ByteRange & shared_info1, const cc7::ByteRange & shared_info2);
330+
ECIESDecryptor(const cc7::crypto::PrivateKeyPtr & private_key, const cc7::ByteRange & shared_info1, const cc7::ByteRange & shared_info2);
330331

331332
/// Constructs a decryptor with previously calculated |envelope_key| and optional |shared_info2|.
332333
/// The constructed instance can be used only for encryption taks.
333334
ECIESDecryptor(const ECIESEnvelopeKey & envelope_key, const cc7::ByteRange & shared_info2);
334335

335336
/// Returns a reference to internal public key.
336-
const cc7::ByteArray & privateKey() const;
337+
const cc7::crypto::PrivateKeyPtr & privateKey() const;
337338

338339
/// Returns a reference to internal envelope key.
339340
const ECIESEnvelopeKey & envelopeKey() const;
@@ -381,7 +382,7 @@ namespace powerAuth
381382

382383
private:
383384
/// A data for private key.
384-
cc7::ByteArray _private_key;
385+
cc7::crypto::PrivateKeyPtr _private_key;
385386
/// Content of shared info1 optional parameter.
386387
cc7::ByteArray _shared_info1;
387388
/// Content of shared info2 optional parameter.

include/PowerAuth/Session.h

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#pragma once
1818

1919
#include <PowerAuth/PublicTypes.h>
20+
#include <cc7/crypto/KeyPair.h>
21+
#include <cc7/crypto/SymmetricKey.h>
2022
#include <map>
2123
#include <mutex>
2224

@@ -682,25 +684,50 @@ namespace powerAuth
682684
Pointer to private persistent data structure. The pointer is valid only
683685
after the correctly finished activation of the session.
684686
*/
685-
protocol::PersistentData * _pd;
687+
std::shared_ptr<protocol::PersistentData> _pd;
686688

687689
/**
688690
Pointer to private activation data structure. The pointer is valid only
689691
during the activation process.
690692
*/
691-
protocol::ActivationData * _ad;
693+
std::shared_ptr<protocol::ActivationData> _ad;
692694

693695
/**
694696
Pointer to private session data structure. The pointer is valid during the whole
695697
Session object lifetime.
696698
*/
697-
protocol::SessionData * _sd;
699+
std::shared_ptr<protocol::SessionData> _sd;
700+
701+
/**
702+
Return reference to device public key. Throws exception when no such key is availabe
703+
in session's state.
704+
*/
705+
const cc7::crypto::PublicKey & getDevicePublicKey() const;
706+
/**
707+
Return reference to server public key. Throws exception when no such key is availabe
708+
in session's state.
709+
*/
710+
const cc7::crypto::PublicKey & getServerPublicKey() const;
711+
/**
712+
Return reference to master server public key.
713+
*/
714+
const cc7::crypto::PublicKey & getMasterServerPublicKey() const;
715+
716+
/**
717+
Calculate activation's shared secret. The server's public key must be available.
718+
*/
719+
cc7::ByteArray calculateSharedSecret(const cc7::crypto::PrivateKey & device_private_key) const;
720+
721+
/**
722+
Retrieve device's private key with vault unlock key.
723+
*/
724+
cc7::crypto::PrivateKeyPtr getDevicePrivateKey(const cc7::ByteRange & vault_unlock_key) const;
698725

699726
/**
700727
Commits a |new_pd| and |new_state| as a new valid session state.
701728
Check documentation in method's implementation for details.
702729
*/
703-
void commitNewPersistentState(protocol::PersistentData * new_pd, State new_state);
730+
void commitNewPersistentState(std::shared_ptr<protocol::PersistentData> new_pd, State new_state);
704731

705732
/**
706733
Changes internal state to a new one. If code is compiled with DEBUG build flags

proj-xcode/PowerAuth2IntegrationTests/PowerAuthSdkTestHelper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ + (void) setupLog
8181
{
8282
if (!PowerAuthLogIsEnabled()) {
8383
PowerAuthLogSetEnabled(YES);
84-
PowerAuthLogSetVerbose(NO);
84+
PowerAuthLogSetVerbose(YES);
8585
}
8686
}
8787

proj-xcode/PowerAuth2IntegrationTests/PowerAuthServer/AsyncHelper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ + (id) synchronizeAsynchronousBlock:(void(^)(AsyncHelper * waiting))block
5757

5858
+ (id) synchronizeAsynchronousBlock:(void(^)(AsyncHelper * waiting))block
5959
{
60-
return [self synchronizeAsynchronousBlock:block wait:10.0];
60+
return [self synchronizeAsynchronousBlock:block wait:100.0];
6161
}
6262

6363
- (void) reportCompletion:(id)resultObject

0 commit comments

Comments
 (0)