Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Commit

Permalink
fixed all compiler warnings related to srp auth
Browse files Browse the repository at this point in the history
  • Loading branch information
boundsj committed Jul 10, 2013
1 parent de534c7 commit cccb0a2
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 44 deletions.
Binary file added Default-568h@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions Example/Example/LoginViewController.m
Expand Up @@ -15,8 +15,8 @@ @implementation LoginViewController
///
struct SRPUser * usr;

SRP_HashAlgorithm alg = SRP_SHA256;
SRP_NGType ng_type = SRP_NG_1024;
SRP_HashAlgorithm algLocal = SRP_SHA256;
SRP_NGType ng_typeLocal = SRP_NG_1024;

#pragma mark <DDPAuthDelegate>

Expand Down Expand Up @@ -104,8 +104,8 @@ - (NSString *)generateVerificationKey {
const char * password_str = [self.password.text cStringUsingEncoding:NSASCIIStringEncoding];

/* Begin authentication process */
usr = srp_user_new(alg,
ng_type,
usr = srp_user_new(algLocal,
ng_typeLocal,
username_str,
password_str,
strlen(password_str),
Expand Down
4 changes: 2 additions & 2 deletions Example/Example/LoginViewController.xib
Expand Up @@ -2,9 +2,9 @@
<archive type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="8.00">
<data>
<int key="IBDocument.SystemTarget">1552</int>
<string key="IBDocument.SystemVersion">12D78</string>
<string key="IBDocument.SystemVersion">12E55</string>
<string key="IBDocument.InterfaceBuilderVersion">3084</string>
<string key="IBDocument.AppKitVersion">1187.37</string>
<string key="IBDocument.AppKitVersion">1187.39</string>
<string key="IBDocument.HIToolboxVersion">626.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
<string key="NS.key.0">com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
Expand Down
9 changes: 4 additions & 5 deletions Example/Podfile.lock
@@ -1,20 +1,19 @@
PODS:
- ObjectiveDDP (0.0.17)
- ObjectiveDDP (0.0.19)
- SocketRocket (0.3.1-beta2)

DEPENDENCIES:
- ObjectiveDDP (from `git@github.com:boundsj/ObjectiveDDP.git`, branch `master`)
- ObjectiveDDP (from `/Users/boundsj/workspace/ios/ObjectiveDDP`)
- SocketRocket (from `git@github.com:square/SocketRocket.git`)

EXTERNAL SOURCES:
ObjectiveDDP:
:branch: master
:git: git@github.com:boundsj/ObjectiveDDP.git
:path: /Users/boundsj/workspace/ios/ObjectiveDDP
SocketRocket:
:git: git@github.com:square/SocketRocket.git

SPEC CHECKSUMS:
ObjectiveDDP: 3a9c17cb081aecf2933d87762546340887be8264
ObjectiveDDP: 79c9f4a96553d21d2756738b7f3ef5916541e039
SocketRocket: 9cbe08469513356cddc0afcab1ff160bd190296a

COCOAPODS: 0.19.1
2 changes: 1 addition & 1 deletion ObjectiveDDP.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'ObjectiveDDP'
s.version = '0.0.17'
s.version = '0.0.20'
s.license = 'MIT'
s.summary = 'Facilitates communication between iOS clients and meteor.js servers'
s.homepage = 'https://github.com/boundsj/ObjectiveDDP.git'
Expand Down
30 changes: 22 additions & 8 deletions ObjectiveDDP.xcodeproj/project.pbxproj
Expand Up @@ -14,8 +14,7 @@
401AEB80170E9ECC008B38EA /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 401AEB7F170E9ECC008B38EA /* SystemConfiguration.framework */; };
401AEB82170E9ED2008B38EA /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 401AEB81170E9ED2008B38EA /* CFNetwork.framework */; };
401AEB84170E9EEB008B38EA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 401AEB83170E9EEB008B38EA /* Security.framework */; };
405FD5F41745DABE001F8AE7 /* libcrypto.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 405FD5A71745DABE001F8AE7 /* libcrypto.a */; };
405FD5F81746BCD5001F8AE7 /* srp.c in Sources */ = {isa = PBXBuildFile; fileRef = 405FD5F61746BCD5001F8AE7 /* srp.c */; };
4027EDE21783E1F400CAEC1C /* srp.c in Sources */ = {isa = PBXBuildFile; fileRef = 405FD5F61746BCD5001F8AE7 /* srp.c */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
4079F9DB170EB31D00194B4A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4079F9DA170EB31D00194B4A /* UIKit.framework */; };
4079F9DC170EB31D00194B4A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4000D639170E880400296229 /* Foundation.framework */; };
4079F9DE170EB31D00194B4A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4079F9DD170EB31D00194B4A /* CoreGraphics.framework */; };
Expand All @@ -28,6 +27,7 @@
4079F9F4170EB36700194B4A /* libicucore.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 401AEB7D170E9EC7008B38EA /* libicucore.dylib */; };
4079F9F5170EB39200194B4A /* ObjectiveDDP.m in Sources */ = {isa = PBXBuildFile; fileRef = 4000D640170E880400296229 /* ObjectiveDDP.m */; };
4079F9F7170EB3B000194B4A /* ObjectiveDDPSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4079F9F6170EB3B000194B4A /* ObjectiveDDPSpec.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
40A305F3178D27E800546C1F /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 40A305F2178D27E800546C1F /* Default-568h@2x.png */; };
40F8370C1741C59700AF2340 /* BSONIdGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = 888B6DFE173B66EA001EED80 /* BSONIdGenerator.m */; };
40F8370D1741C59700AF2340 /* MeteorClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 888B6DFB173B6508001EED80 /* MeteorClient.m */; };
40F8370F1741C62800AF2340 /* MeteorClientSpec.mm in Sources */ = {isa = PBXBuildFile; fileRef = 40F8370E1741C62800AF2340 /* MeteorClientSpec.mm */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
Expand Down Expand Up @@ -152,6 +152,7 @@
4079F9E7170EB31D00194B4A /* Specs-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Specs-Prefix.pch"; sourceTree = "<group>"; };
4079F9E8170EB31E00194B4A /* Cedar-iOS.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = "Cedar-iOS.framework"; path = "Specs/Frameworks/Cedar-iOS.framework"; sourceTree = "<group>"; };
4079F9F6170EB3B000194B4A /* ObjectiveDDPSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ObjectiveDDPSpec.mm; sourceTree = "<group>"; };
40A305F2178D27E800546C1F /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
40F8370E1741C62800AF2340 /* MeteorClientSpec.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MeteorClientSpec.mm; sourceTree = "<group>"; };
430E02ACD0BC78CC53F31D72 /* MockSRWebSocket.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MockSRWebSocket.m; sourceTree = "<group>"; };
430E092B95390D2D558E5F3B /* MockObjectiveDDPDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MockObjectiveDDPDelegate.m; sourceTree = "<group>"; };
Expand All @@ -173,7 +174,6 @@
401AEB82170E9ED2008B38EA /* CFNetwork.framework in Frameworks */,
401AEB80170E9ECC008B38EA /* SystemConfiguration.framework in Frameworks */,
4000D63A170E880400296229 /* Foundation.framework in Frameworks */,
405FD5F41745DABE001F8AE7 /* libcrypto.a in Frameworks */,
401AEB7E170E9EC7008B38EA /* libicucore.dylib in Frameworks */,
9D3C062D54114FB1AC5700F0 /* libPods.a in Frameworks */,
);
Expand All @@ -183,14 +183,14 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
4079F9F4170EB36700194B4A /* libicucore.dylib in Frameworks */,
4079F9F3170EB36000194B4A /* SystemConfiguration.framework in Frameworks */,
4079F9F2170EB35800194B4A /* CFNetwork.framework in Frameworks */,
4079F9F1170EB35200194B4A /* Security.framework in Frameworks */,
4079F9DB170EB31D00194B4A /* UIKit.framework in Frameworks */,
4079F9DC170EB31D00194B4A /* Foundation.framework in Frameworks */,
4079F9DE170EB31D00194B4A /* CoreGraphics.framework in Frameworks */,
4079F9E9170EB31E00194B4A /* Cedar-iOS.framework in Frameworks */,
4079F9F4170EB36700194B4A /* libicucore.dylib in Frameworks */,
570DE62F4BD74C18AE51ED8C /* libPods.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -201,6 +201,7 @@
4000D62D170E880400296229 = {
isa = PBXGroup;
children = (
40A305F2178D27E800546C1F /* Default-568h@2x.png */,
4000D63B170E880400296229 /* ObjectiveDDP */,
4079F9DF170EB31D00194B4A /* Specs */,
4000D638170E880400296229 /* Frameworks */,
Expand Down Expand Up @@ -345,19 +346,19 @@
405FD5F51746BCD5001F8AE7 /* srp */ = {
isa = PBXGroup;
children = (
405FD5F61746BCD5001F8AE7 /* srp.c */,
405FD5F71746BCD5001F8AE7 /* srp.h */,
405FD5F61746BCD5001F8AE7 /* srp.c */,
);
path = srp;
sourceTree = "<group>";
};
4079F9DF170EB31D00194B4A /* Specs */ = {
isa = PBXGroup;
children = (
40F8370E1741C62800AF2340 /* MeteorClientSpec.mm */,
4079F9F6170EB3B000194B4A /* ObjectiveDDPSpec.mm */,
4079F9E0170EB31D00194B4A /* Supporting Files */,
430E092A40EC4FAED3B6C76B /* Mocks */,
40F8370E1741C62800AF2340 /* MeteorClientSpec.mm */,
4079F9E0170EB31D00194B4A /* Supporting Files */,
);
path = Specs;
sourceTree = "<group>";
Expand Down Expand Up @@ -457,6 +458,7 @@
buildActionMask = 2147483647;
files = (
4079F9E4170EB31D00194B4A /* InfoPlist.strings in Resources */,
40A305F3178D27E800546C1F /* Default-568h@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -501,7 +503,6 @@
4000D641170E880400296229 /* ObjectiveDDP.m in Sources */,
888B6DFC173B6508001EED80 /* MeteorClient.m in Sources */,
888B6DFF173B66EA001EED80 /* BSONIdGenerator.m in Sources */,
405FD5F81746BCD5001F8AE7 /* srp.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -517,6 +518,7 @@
430E08B6E86CA801EE954D0F /* MockObjectiveDDPDelegate.m in Sources */,
430E014E41C9666E08613FCE /* MockSRWebSocket.m in Sources */,
40F8370F1741C62800AF2340 /* MeteorClientSpec.mm in Sources */,
4027EDE21783E1F400CAEC1C /* srp.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -636,11 +638,17 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Specs/Specs-Prefix.pch";
HEADER_SEARCH_PATHS = "${PODS_HEADERS_SEARCH_PATHS}";
INFOPLIST_FILE = "Specs/Specs-Info.plist";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/ObjectiveDDP\"",
);
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
"-lstdc++",
"-lcrypto",
);
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand All @@ -658,12 +666,18 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "Specs/Specs-Prefix.pch";
HEADER_SEARCH_PATHS = "${PODS_HEADERS_SEARCH_PATHS}";
INFOPLIST_FILE = "Specs/Specs-Info.plist";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/ObjectiveDDP\"",
);
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
OTHER_LDFLAGS = (
"-ObjC",
"-all_load",
"-lstdc++",
"-lcrypto",
);
PRODUCT_NAME = "$(TARGET_NAME)";
WRAPPER_EXTENSION = app;
Expand Down
Expand Up @@ -57,6 +57,13 @@
ReferencedContainer = "container:ObjectiveDDP.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "CEDAR_HEADLESS_SPECS"
value = ""
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
Expand Down
4 changes: 4 additions & 0 deletions ObjectiveDDP/MeteorClient.h
Expand Up @@ -14,6 +14,10 @@
- (void)addSubscription:(NSString *)subscriptionName;
- (void)resetCollections;

// TODO: These methods are only temporarily public, should be impl detail of MeteorClient
- (NSString *)generateAuthVerificationKeyWithUsername:(NSString *)username password:(NSString *)password;
//- (void)processMeteorChallenge

@end

@protocol DDPAuthDelegate <NSObject>
Expand Down
40 changes: 40 additions & 0 deletions ObjectiveDDP/MeteorClient.m
@@ -1,5 +1,12 @@
#import "MeteorClient.h"
#import "BSONIdGenerator.h"
#import "srp/srp.h"

@interface MeteorClient ()

@property (assign, nonatomic) struct SRPUser *usr;

@end

@implementation MeteorClient

Expand Down Expand Up @@ -142,4 +149,37 @@ - (void)_parseRemoved:(NSDictionary *)message {
[collection removeObjectAtIndex:indexOfRemovedObject];
}

# pragma mark Meteor DDP Wrapper

SRP_HashAlgorithm alg = SRP_SHA256;
SRP_NGType ng_type = SRP_NG_1024;

- (NSString *)generateAuthVerificationKeyWithUsername:(NSString *)username password:(NSString *)password {
//TODO: don't really need to keep bytes_A and len_A here, could remove them
// and push into srp lib
const unsigned char * bytes_A = 0;
int len_A = 0;
const char * Astr = 0;
const char * auth_username = 0;
const char * username_str = [username cStringUsingEncoding:NSASCIIStringEncoding];
const char * password_str = [password cStringUsingEncoding:NSASCIIStringEncoding];

/* Begin authentication process */
self.usr = srp_user_new(alg,
ng_type,
username_str,
password_str,
strlen(password_str),
NULL,
NULL);

srp_user_start_authentication(self.usr,
&auth_username,
&bytes_A,
&len_A,
&Astr);

return [NSString stringWithCString:Astr encoding:NSASCIIStringEncoding];
}

@end
6 changes: 3 additions & 3 deletions ObjectiveDDP/openssl/srp.h
Expand Up @@ -68,9 +68,9 @@
extern "C" {
#endif

#include <openssl/safestack.h>
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <safestack.h>
#include <bn.h>
#include <crypto.h>

typedef struct SRP_gN_cache_st
{
Expand Down
42 changes: 21 additions & 21 deletions ObjectiveDDP/srp/srp.c
Expand Up @@ -813,11 +813,11 @@ void meteor_user_generate_u( struct SRPUser *usr,
unsigned char *buff,
BIGNUM **u )
{
char *catString_u = malloc( strlen(usr->Astr)+strlen(Bstr)+1 );
strcpy( catString_u, usr->Astr );
strcat( catString_u, Bstr );
unsigned char *catString_u = malloc( strlen(usr->Astr)+strlen(Bstr)+1 );
strcpy((char *)catString_u, usr->Astr);
strcat( (char *)catString_u, Bstr);

hash( usr->hash_alg, catString_u, strlen(catString_u), buff );
hash( usr->hash_alg, catString_u, strlen((char *)catString_u), buff );
*u = BN_bin2bn(buff, hash_length(usr->hash_alg), NULL);
}

Expand All @@ -831,12 +831,12 @@ void meteor_user_generate_x( struct SRPUser *usr,
const char * static_delim = ":";
BIGNUM * x_inner = 0;

const char * catString_i_p = malloc(strlen(identity) + strlen(password) + 1);
strcpy(catString_i_p, identity);
strcat(catString_i_p, static_delim);
strcat(catString_i_p, password);
const unsigned char * catString_i_p = malloc(strlen(identity) + strlen(password) + 1);
strcpy((char *)catString_i_p, identity);
strcat((char *)catString_i_p, static_delim);
strcat((char *)catString_i_p, password);

hash( usr->hash_alg, catString_i_p, strlen(catString_i_p), buff );
hash( usr->hash_alg, catString_i_p, strlen((char *)catString_i_p), buff );
x_inner = BN_bin2bn(buff, hash_length(usr->hash_alg), NULL);

if ( !x_inner )
Expand All @@ -846,11 +846,11 @@ void meteor_user_generate_x( struct SRPUser *usr,
const char * x_inner_str = BN_bn2hex(x_inner);
char * x_inner_str_lower = convert_to_lower(x_inner_str);

char * catString_s_i_p = malloc(strlen(salt) + strlen(x_inner_str_lower) + 1);
strcpy(catString_s_i_p, salt);
strcat(catString_s_i_p, x_inner_str_lower);
const unsigned char * catString_s_i_p = malloc(strlen(salt) + strlen(x_inner_str_lower) + 1);
strcpy((char *)catString_s_i_p, salt);
strcat((char *)catString_s_i_p, x_inner_str_lower);

hash( usr->hash_alg, catString_s_i_p, strlen(catString_s_i_p), buff );
hash( usr->hash_alg, catString_s_i_p, strlen((char *)catString_s_i_p), buff );
*x = BN_bin2bn(buff, hash_length(usr->hash_alg), NULL);

cleanup_and_exit:
Expand All @@ -872,8 +872,8 @@ void meteor_user_generate_k( struct SRPUser *usr,
strcpy( cat_string_n_g, N_str );
strcat( cat_string_n_g, g_str );

char * ng = convert_to_lower( cat_string_n_g );
hash( usr->hash_alg, ng, strlen(ng), buff );
const char * ng = convert_to_lower( cat_string_n_g );
hash( usr->hash_alg, (const unsigned char *)ng, strlen(ng), buff );

*k = BN_bin2bn( buff, hash_length(usr->hash_alg), NULL );
}
Expand Down Expand Up @@ -925,9 +925,9 @@ void meteor_user_generate_S_string( struct SRPUser *usr,
const char * B_str,
char ** S_str)
{
BIGNUM const *B = BN_new();
BIGNUM *bkgx = BN_new();
BIGNUM *S = BN_new();
BIGNUM *B = BN_new();
BIGNUM *bkgx = BN_new();
BIGNUM *S = BN_new();

BN_hex2bn( &B, B_str );

Expand Down Expand Up @@ -966,7 +966,7 @@ void meteor_user_generate_M_string( struct SRPUser *usr,
strcat(ABS, B_str);
strcat(ABS, S_str);

hash( usr->hash_alg, ABS, strlen(ABS), buff );
hash( usr->hash_alg, (const unsigned char *)ABS, strlen(ABS), buff );

M = BN_bin2bn( buff, hash_length(usr->hash_alg), NULL );

Expand All @@ -990,7 +990,7 @@ void meteor_user_generate_HAMK( struct SRPUser *usr,
strcat( AMS, M_str );
strcat( AMS, S_str );

hash( usr->hash_alg, AMS, strlen(AMS), buff );
hash( usr->hash_alg, (const unsigned char *)AMS, strlen(AMS), buff );
usr->HAMK = convert_to_lower( BN_bn2hex(BN_bin2bn(buff, hash_length(usr->hash_alg), NULL)) );
}

Expand Down Expand Up @@ -1044,7 +1044,7 @@ void srp_user_process_meteor_challenge( struct SRPUser * usr,
if ( !S_str )
goto cleanup_and_exit;

const char * M_str;
char * M_str;
meteor_user_generate_M_string( usr, S_str, buff, Bstr, &M_str );
*Mstr = M_str;

Expand Down

0 comments on commit cccb0a2

Please sign in to comment.