Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feature/642-async-…
Browse files Browse the repository at this point in the history
…interfaces
  • Loading branch information
hvge committed Feb 18, 2025
2 parents 3820e53 + 4f8e385 commit 49ee3ed
Show file tree
Hide file tree
Showing 44 changed files with 874 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public enum ProtocolVersion {
V3(30, "3.0"),
V3_1(31, "3.1"),
V3_2(32, "3.2"),
V3_3(33, "3.3");
V3_3(33, "3.3"),
V4_0(40, "4.0");

public final int version;
public final String versionForHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ public enum ServerVersion {
V1_8_0("1.8", 1008000, ProtocolVersion.V3_2),
V1_9_0("1.9", 1009000, ProtocolVersion.V3_3),
V1_10_0("1.10", 1010000, ProtocolVersion.V3_3),
V2_0_0("2.0", 2000000, ProtocolVersion.V4_0),
;

/**
* Contains constant for the latest PowerAuth Server version.
*/
public static final ServerVersion LATEST = V1_10_0;
public static final ServerVersion LATEST = V2_0_0;

/**
* Server version represented as string.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ typedef NS_ENUM(int, PowerAuthTestServerVersion) {
PATS_V1_8 = 10800, // V3.2 crypto + Activation OTP, applicationId as String, userInfo
PATS_V1_9 = 10900, // V3.3 crypto + Activation OTP, applicationId as String, userInfo, temporary keys
PATS_V1_10 = 11000, // V3.3 crypto + Activation OTP, applicationId as String, userInfo, temporary keys
PATS_V2_0 = 20000, // V4.0 crypto
};

/**
Expand All @@ -44,6 +45,7 @@ typedef NS_ENUM(int, PowerAuthProtocolVersion) {
PATS_P31, // V3.1 crypto
PATS_P32, // V3.2 crypto
PATS_P33, // V3.3 crypto
PATS_P40, // V4.0 crypto
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"1.7" : "v15",
"1.8" : "v15",
"1.9" : "v19",
"1.10": "v19",
"2.0" : "v20",

"*" : "v19"
"*" : "v20"
},
"mappings": {
"v10": {
Expand Down Expand Up @@ -44,6 +46,8 @@
"CreateApplicationVersion": "CreateApplicationVersion_v15",
"TokenValidate": "TokenValidate_v15",
"VerifyECDSASignature": "VerifyECDSASignature_v19"
},
"v20": { "#base": "v19",
}
}
}
14 changes: 10 additions & 4 deletions proj-xcode/PowerAuthCore.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
BF99D90F2073E15100735ED2 /* KDF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF99D8D52073E00D00735ED2 /* KDF.cpp */; };
BF99D9102073E15100735ED2 /* MAC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF99D8DB2073E00D00735ED2 /* MAC.cpp */; };
BF99D91E2073E28900735ED2 /* g_pa2Files.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BF99D8BB2073E00D00735ED2 /* g_pa2Files.cpp */; };
BFA85D552D43F27500E60260 /* OSSLObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BFA85D542D43F27300E60260 /* OSSLObjects.cpp */; };
BFA85D562D43F27500E60260 /* OSSLObjects.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BFA85D542D43F27300E60260 /* OSSLObjects.cpp */; };
BFA98090253DA559004D2CF9 /* PowerAuthCorePassword.mm in Sources */ = {isa = PBXBuildFile; fileRef = BFA9807A253DA559004D2CF9 /* PowerAuthCorePassword.mm */; };
BFA98091253DA559004D2CF9 /* PowerAuthCorePassword.mm in Sources */ = {isa = PBXBuildFile; fileRef = BFA9807A253DA559004D2CF9 /* PowerAuthCorePassword.mm */; };
BFA98092253DA559004D2CF9 /* PowerAuthCoreMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = BFA9807C253DA559004D2CF9 /* PowerAuthCoreMacros.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -424,7 +426,7 @@
BF99D8D32073E00D00735ED2 /* PRNG.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PRNG.h; sourceTree = "<group>"; };
BF99D8D42073E00D00735ED2 /* PKCS7Padding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PKCS7Padding.h; sourceTree = "<group>"; };
BF99D8D52073E00D00735ED2 /* KDF.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = KDF.cpp; sourceTree = "<group>"; };
BF99D8D62073E00D00735ED2 /* BNContext.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BNContext.h; sourceTree = "<group>"; };
BF99D8D62073E00D00735ED2 /* LLObject.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LLObject.h; sourceTree = "<group>"; };
BF99D8D72073E00D00735ED2 /* CryptoUtils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CryptoUtils.h; sourceTree = "<group>"; };
BF99D8D82073E00D00735ED2 /* PRNG.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = PRNG.cpp; sourceTree = "<group>"; };
BF99D8D92073E00D00735ED2 /* AES.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AES.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -456,6 +458,8 @@
BF99D8FF2073E00D00735ED2 /* ECIES.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ECIES.cpp; sourceTree = "<group>"; };
BF99D9152073E17000735ED2 /* libPowerAuthCoreLibTests-ios.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPowerAuthCoreLibTests-ios.a"; sourceTree = BUILT_PRODUCTS_DIR; };
BF9AFF062992707900400D5B /* signatures-offline.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "signatures-offline.json"; sourceTree = "<group>"; };
BFA85D532D43F26300E60260 /* OSSLObjects.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSSLObjects.h; sourceTree = "<group>"; };
BFA85D542D43F27300E60260 /* OSSLObjects.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = OSSLObjects.cpp; sourceTree = "<group>"; };
BFA9807A253DA559004D2CF9 /* PowerAuthCorePassword.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PowerAuthCorePassword.mm; sourceTree = "<group>"; };
BFA9807B253DA559004D2CF9 /* core.modulemap */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "sourcecode.module-map"; path = core.modulemap; sourceTree = "<group>"; };
BFA9807C253DA559004D2CF9 /* PowerAuthCoreMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PowerAuthCoreMacros.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -742,8 +746,10 @@
BF99D8D12073E00D00735ED2 /* crypto */ = {
isa = PBXGroup;
children = (
BF99D8D62073E00D00735ED2 /* LLObject.h */,
BFA85D532D43F26300E60260 /* OSSLObjects.h */,
BFA85D542D43F27300E60260 /* OSSLObjects.cpp */,
BF99D8D72073E00D00735ED2 /* CryptoUtils.h */,
BF99D8D62073E00D00735ED2 /* BNContext.h */,
BF99D8D42073E00D00735ED2 /* PKCS7Padding.h */,
BF99D8DF2073E00D00735ED2 /* PKCS7Padding.cpp */,
BF99D8D32073E00D00735ED2 /* PRNG.h */,
Expand Down Expand Up @@ -1264,6 +1270,7 @@
files = (
BF99D90B2073E15100735ED2 /* PRNG.cpp in Sources */,
BF99D9102073E15100735ED2 /* MAC.cpp in Sources */,
BFA85D552D43F27500E60260 /* OSSLObjects.cpp in Sources */,
BF99D9052073E14100735ED2 /* OtpUtil.cpp in Sources */,
BF99D9032073E14100735ED2 /* Password.cpp in Sources */,
BFB47D1720753324008A6A52 /* DataWriter.cpp in Sources */,
Expand Down Expand Up @@ -1327,6 +1334,7 @@
files = (
BF6ADD6B24C84C0C001B3E5E /* PRNG.cpp in Sources */,
BF6ADD6C24C84C0C001B3E5E /* MAC.cpp in Sources */,
BFA85D562D43F27500E60260 /* OSSLObjects.cpp in Sources */,
BF6ADD6D24C84C0C001B3E5E /* OtpUtil.cpp in Sources */,
BF6ADD6E24C84C0C001B3E5E /* Password.cpp in Sources */,
BF6ADD6F24C84C0C001B3E5E /* DataWriter.cpp in Sources */,
Expand Down Expand Up @@ -1538,7 +1546,6 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand Down Expand Up @@ -1610,7 +1617,6 @@
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
CODE_SIGN_IDENTITY = "iPhone Developer";
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_USER_SCRIPT_SANDBOXING = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1600"
LastUpgradeVersion = "1620"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
51 changes: 19 additions & 32 deletions proj-xcode/PowerAuthCore/PowerAuthCoreCryptoUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
#pragma mark - Private interfaces -

@interface PowerAuthCoreECPublicKey (Private)
@property (nonatomic, readonly) EC_KEY * ecKeyRef;
@property (nonatomic, readonly) crypto::EVPKeyPair * ecKeyRef;
@end

@interface PowerAuthCoreECPrivateKey (Private)
@property (nonatomic, readonly) EC_KEY * ecKeyRef;
@property (nonatomic, readonly) crypto::EVPKeyPair * ecKeyRef;
@end

#pragma mark -
Expand All @@ -41,15 +41,15 @@ + (BOOL) ecdsaValidateSignature:(NSData *)signature
{
auto cpp_data = cc7::objc::CopyFromNSData(data);
auto cpp_signature = cc7::objc::CopyFromNSData(signature);
return (BOOL) crypto::ECDSA_ValidateSignature(cpp_data, cpp_signature, publicKey.ecKeyRef);
return (BOOL) crypto::ECDSA_ValidateSignature(cpp_data, cpp_signature, *publicKey.ecKeyRef);
}

+ (nullable NSData*) ecdsaComputeSignature:(nonnull NSData*)data
withPrivateKey:(nonnull PowerAuthCoreECPrivateKey*)privateKey
{
auto cpp_data = cc7::objc::CopyFromNSData(data);
cc7::ByteArray cpp_signature;
if (crypto::ECDSA_ComputeSignature(cpp_data, privateKey.ecKeyRef, cpp_signature)) {
if (crypto::ECDSA_ComputeSignature(cpp_data, *privateKey.ecKeyRef, cpp_signature)) {
return cc7::objc::CopyToNSData(cpp_signature);
}
return nil;
Expand All @@ -58,7 +58,7 @@ + (nullable NSData*) ecdsaComputeSignature:(nonnull NSData*)data
+ (nullable NSData*) ecdhComputeSharedSecret:(nonnull PowerAuthCoreECPublicKey*)publicKey
withPrivateKey:(nonnull PowerAuthCoreECPrivateKey*)privateKey
{
auto shared_secret = crypto::ECDH_SharedSecret(publicKey.ecKeyRef, privateKey.ecKeyRef);
auto shared_secret = crypto::ECDH_SharedSecret(*publicKey.ecKeyRef, *privateKey.ecKeyRef);
if (shared_secret.empty()) {
return nil;
}
Expand All @@ -67,13 +67,12 @@ + (nullable NSData*) ecdhComputeSharedSecret:(nonnull PowerAuthCoreECPublicKey*)

+ (nullable PowerAuthCoreECKeyPair*) ecGenerateKeyPair
{
EC_KEY * key_pair = crypto::ECC_GenerateKeyPair();
if (key_pair == nullptr) {
auto key_pair = crypto::ECC_GenerateKeyPair(crypto::EllipticCurve::P256);
if (!key_pair.isValid()) {
return nil;
}
crypto::BNContext context;
auto public_key_bytes = crypto::ECC_ExportPublicKey(key_pair, context);
auto private_key_bytes = crypto::ECC_ExportPrivateKey(key_pair, context);
auto public_key_bytes = crypto::ECC_ExportPublicKey(key_pair);
auto private_key_bytes = crypto::ECC_ExportPrivateKey(key_pair);
if (public_key_bytes.empty() || private_key_bytes.empty()) {
return nil;
}
Expand Down Expand Up @@ -120,30 +119,24 @@ + (nullable NSData*) randomBytes:(NSUInteger)count

@implementation PowerAuthCoreECPublicKey
{
EC_KEY * _key;
}

- (void) dealloc
{
EC_KEY_free(_key);
_key = nullptr;
crypto::EVPKeyPair _key;
}

- (id) initWithData:(NSData *)publicKeyData
{
self = [super init];
if (self) {
_key = crypto::ECC_ImportPublicKey(nullptr, cc7::objc::CopyFromNSData(publicKeyData));
if (!_key) {
_key = crypto::ECC_ImportPublicKey(crypto::EllipticCurve::P256, cc7::objc::CopyFromNSData(publicKeyData));
if (!_key.isValid()) {
return nil;
}
}
return self;
}

- (EC_KEY*) ecKeyRef
- (crypto::EVPKeyPair *) ecKeyRef
{
return _key;
return &_key;
}

- (NSData*) publicKeyBytes
Expand All @@ -158,30 +151,24 @@ - (NSData*) publicKeyBytes

@implementation PowerAuthCoreECPrivateKey
{
EC_KEY * _key;
}

- (void) dealloc
{
EC_KEY_free(_key);
_key = nullptr;
crypto::EVPKeyPair _key;
}

- (id) initWithData:(NSData *)privateKeyData
{
self = [super init];
if (self) {
_key = crypto::ECC_ImportPrivateKey(nullptr, cc7::objc::CopyFromNSData(privateKeyData));
if (!_key) {
_key = crypto::ECC_ImportPrivateKey(crypto::EllipticCurve::P256, cc7::objc::CopyFromNSData(privateKeyData));
if (!_key.isValid()) {
return nil;
}
}
return self;
}

- (EC_KEY*) ecKeyRef
- (crypto::EVPKeyPair *) ecKeyRef
{
return _key;
return &_key;
}

- (NSData*) privateKeyBytes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ - (void) testEcdsaComputeSignature
NSMutableData * testData = [[PowerAuthCoreCryptoUtils randomBytes:128] mutableCopy];
XCTAssertNotNil(testData);
NSData * signature = [PowerAuthCoreCryptoUtils ecdsaComputeSignature:testData withPrivateKey:keyPair.privateKey];
NSLog(@"Data: %@", [testData base64EncodedStringWithOptions:0]);
NSLog(@"PubK: %@", [keyPair.publicKey.publicKeyBytes base64EncodedStringWithOptions:0]);
NSLog(@"Sign: %@", [signature base64EncodedStringWithOptions:0]);
BOOL result = [PowerAuthCoreCryptoUtils ecdsaValidateSignature:signature forData:testData forPublicKey:keyPair.publicKey];
XCTAssertTrue(result);
unsigned char * bytePtr = (unsigned char *)[testData mutableBytes];
Expand Down
1 change: 1 addition & 0 deletions src/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ LOCAL_SRC_FILES := \
PowerAuth/crypto/KDF.cpp \
PowerAuth/crypto/MAC.cpp \
PowerAuth/crypto/ECC.cpp \
PowerAuth/crypto/OSSLObjects.cpp \
PowerAuth/crypto/PKCS7Padding.cpp \
PowerAuth/crypto/PRNG.cpp \
PowerAuth/protocol/Constants.cpp \
Expand Down
Loading

0 comments on commit 49ee3ed

Please sign in to comment.