forked from couchbaselabs/iOS-Couchbase
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds an admin account/password for better security.
- On first launch, create an admin account with a randomly generated password. - Disable all anonymous access (even reads). - New CouchbaseMobile.adminCredential to get the username/ password. Change-Id: Ibbdd62ce4d5aaafd025a4e4a744486a669a463d8 Reviewed-on: http://review.couchbase.org/10826 Tested-by: Farshid Ghods <farshid.ghods@gmail.com> Reviewed-by: Jens Alfke <jens@couchbase.com>
- Loading branch information
Showing
9 changed files
with
420 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// RESTBase64.h | ||
// CouchCocoa | ||
// | ||
// Created by Jens Alfke on 9/14/11. | ||
// Copyright (c) 2011 Couchbase, Inc. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface RESTBase64 : NSObject | ||
+ (NSString*) encode:(const void*) input length:(size_t) length; | ||
+ (NSString*) encode:(NSData*) rawBytes; | ||
+ (NSData*) decode:(const char*) string length:(size_t) inputLength; | ||
+ (NSData*) decode:(NSString*) string; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// | ||
// RESTBase64.m | ||
// CouchCocoa | ||
// | ||
// Created by Jens Alfke on 9/14/11. | ||
// Copyright (c) 2011 Couchbase, Inc. All rights reserved. | ||
// | ||
|
||
#import "RESTBase64.h" | ||
|
||
// Based on public-domain source code by cyrus.najmabadi@gmail.com | ||
// taken from http://www.cocoadev.com/index.pl?BaseSixtyFour | ||
|
||
|
||
@implementation RESTBase64 | ||
|
||
|
||
static const uint8_t kEncodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
static int8_t kDecodingTable[256]; | ||
|
||
+ (void) initialize { | ||
if (self == [RESTBase64 class]) { | ||
memset(kDecodingTable, 0xFF, sizeof(kDecodingTable)); | ||
for (NSInteger i = 0; i < sizeof(kEncodingTable); i++) { | ||
kDecodingTable[kEncodingTable[i]] = i; | ||
} | ||
} | ||
} | ||
|
||
|
||
+ (NSString*) encode: (const void*)input length: (size_t)length { | ||
if (input == NULL) | ||
return nil; | ||
NSMutableData* data = [NSMutableData dataWithLength:((length + 2) / 3) * 4]; | ||
uint8_t* output = (uint8_t*)data.mutableBytes; | ||
|
||
for (NSInteger i = 0; i < length; i += 3) { | ||
NSInteger value = 0; | ||
for (NSInteger j = i; j < (i + 3); j++) { | ||
value <<= 8; | ||
|
||
if (j < length) { | ||
value |= ((const uint8_t*)input)[j]; | ||
} | ||
} | ||
|
||
NSInteger index = (i / 3) * 4; | ||
output[index + 0] = kEncodingTable[(value >> 18) & 0x3F]; | ||
output[index + 1] = kEncodingTable[(value >> 12) & 0x3F]; | ||
output[index + 2] = (i + 1) < length ? kEncodingTable[(value >> 6) & 0x3F] : '='; | ||
output[index + 3] = (i + 2) < length ? kEncodingTable[(value >> 0) & 0x3F] : '='; | ||
} | ||
|
||
return [[[NSString alloc] initWithData:data | ||
encoding:NSASCIIStringEncoding] autorelease]; | ||
} | ||
|
||
|
||
+ (NSString*) encode: (NSData*)rawBytes { | ||
return [self encode: rawBytes.bytes length: rawBytes.length]; | ||
} | ||
|
||
|
||
+ (NSData*) decode: (const char*)string length: (size_t)inputLength { | ||
if ((string == NULL) || (inputLength % 4 != 0)) { | ||
return nil; | ||
} | ||
|
||
while (inputLength > 0 && string[inputLength - 1] == '=') { | ||
inputLength--; | ||
} | ||
|
||
size_t outputLength = inputLength * 3 / 4; | ||
NSMutableData* data = [NSMutableData dataWithLength:outputLength]; | ||
uint8_t* output = data.mutableBytes; | ||
|
||
NSInteger inputPoint = 0; | ||
NSInteger outputPoint = 0; | ||
while (inputPoint < inputLength) { | ||
uint8_t i0 = string[inputPoint++]; | ||
uint8_t i1 = string[inputPoint++]; | ||
uint8_t i2 = inputPoint < inputLength ? string[inputPoint++] : 'A'; /* 'A' will decode to \0 */ | ||
uint8_t i3 = inputPoint < inputLength ? string[inputPoint++] : 'A'; | ||
|
||
if (kDecodingTable[i0] < 0 || kDecodingTable[i1] < 0 | ||
|| kDecodingTable[i2] < 0 || kDecodingTable[i3] < 0) | ||
return nil; | ||
|
||
output[outputPoint++] = (kDecodingTable[i0] << 2) | (kDecodingTable[i1] >> 4); | ||
if (outputPoint < outputLength) { | ||
output[outputPoint++] = ((kDecodingTable[i1] & 0xf) << 4) | (kDecodingTable[i2] >> 2); | ||
} | ||
if (outputPoint < outputLength) { | ||
output[outputPoint++] = ((kDecodingTable[i2] & 0x3) << 6) | kDecodingTable[i3]; | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
|
||
+ (NSData*) decode:(NSString*) string { | ||
NSData* ascii = [string dataUsingEncoding: NSASCIIStringEncoding]; | ||
return [self decode: ascii.bytes length: ascii.length]; | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// TestConnection.h | ||
// Empty App | ||
// | ||
// Created by Jens Alfke on 11/11/11. | ||
// Copyright (c) 2011 CouchBase, Inc. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
/** A simple class that sends synchronous HTTP requests using NSURLConnection. */ | ||
@interface TestConnection : NSObject <NSURLConnectionDataDelegate> | ||
{ | ||
NSMutableURLRequest* _request; | ||
NSHTTPURLResponse* _response; | ||
NSMutableData* _responseBody; | ||
NSError* _error; | ||
BOOL _loading; | ||
} | ||
|
||
+ (TestConnection*) connectionWithMethod: (NSString*)method | ||
path: (NSString*)relativePath | ||
body: (NSString*)body; | ||
|
||
@property (readonly) NSURL* URL; | ||
|
||
- (BOOL) run; | ||
|
||
@property (readonly) NSHTTPURLResponse* response; | ||
@property (readonly) NSData* responseBody; | ||
@property (readonly) NSString* responseString; | ||
@property (readonly) NSError* error; | ||
|
||
@end |
Oops, something went wrong.