This repository has been archived by the owner on Feb 13, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOTPAuthURL.h
97 lines (79 loc) · 3.21 KB
/
OTPAuthURL.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// OTPAuthURL.h
//
// Copyright 2011 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
//
#import <Foundation/Foundation.h>
@class OTPGenerator;
// This class encapsulates the parsing of otpauth:// urls, the creation of
// either HOTPGenerator or TOTPGenerator objects, and the persistence of the
// objects state to the iPhone keychain in a secure fashion.
//
// The secret key is stored as the "password" in the keychain item, and the
// re-constructed URL is stored in an attribute.
@interface OTPAuthURL : NSObject
// |name| is an arbitrary UTF8 text string extracted from the url path.
@property(readwrite, copy, nonatomic) NSString *name;
@property(readonly, nonatomic) NSString *otpCode;
@property(readonly, nonatomic) NSString *checkCode;
@property(readonly, retain, nonatomic) NSData *keychainItemRef;
// Standard base32 alphabet.
// Input is case insensitive.
// No padding is used.
// Ignore space and hyphen (-).
// For details on use, see android app:
// http://google3/security/strongauth/mobile/android/StrongAuth/src/org/strongauth/Base32String.java
+ (NSData *)base32Decode:(NSString *)string;
+ (NSString *)encodeBase32:(NSData *)data;
+ (OTPAuthURL *)authURLWithURL:(NSURL *)url
secret:(NSData *)secret;
+ (OTPAuthURL *)authURLWithKeychainItemRef:(NSData *)keychainItemRef;
// Returns a reconstructed NSURL object representing the current state of the
// |generator|.
- (NSURL *)url;
// Saves the current object state to the keychain.
- (BOOL)saveToKeychain;
// Removes the current object state from the keychain.
- (BOOL)removeFromKeychain;
// Returns true if the object was loaded from or subsequently added to the
// iPhone keychain.
// It does not assert that the keychain is up to date with the latest
// |generator| state.
- (BOOL)isInKeychain;
- (NSString*)checkCode;
@end
@interface TOTPAuthURL : OTPAuthURL {
@private
NSTimeInterval generationAdvanceWarning_;
NSTimeInterval lastProgress_;
BOOL warningSent_;
}
@property(readwrite, assign, nonatomic) NSTimeInterval generationAdvanceWarning;
- (id)initWithSecret:(NSData *)secret name:(NSString *)name;
@end
@interface HOTPAuthURL : OTPAuthURL {
@private
NSString *otpCode_;
}
- (id)initWithSecret:(NSData *)secret name:(NSString *)name;
- (void)generateNextOTPCode;
@end
// Notification sent out |otpGenerationAdvanceWarning_| before a new OTP is
// generated. Only applies to TOTP Generators. Has a
// |OTPAuthURLSecondsBeforeNewOTPKey| key which is a NSNumber with the
// number of seconds remaining before the new OTP is generated.
extern NSString *const OTPAuthURLWillGenerateNewOTPWarningNotification;
extern NSString *const OTPAuthURLSecondsBeforeNewOTPKey;
extern NSString *const OTPAuthURLDidGenerateNewOTPNotification;