Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dkocher committed Sep 6, 2006
1 parent 77a995c commit da2a709
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions source/ch/cyberduck/core/Login.java
Expand Up @@ -39,12 +39,25 @@ public Object clone() {
}

private String hostname;
/**
* See #Session
*/
private String protocol;
private String user;
private transient String pass;
/**
* If not null, use public key authentication if SSH is the protocol
*/
private String privateKeyFile;
private boolean shouldBeAddedToKeychain;

/**
* ProtocolTypeConstants as defined in SecKeychain.h; see #708
*/
private static final String kSecProtocolTypeFTP = "ftp ";
private static final String kSecProtocolTypeFTPS = "ftps";
private static final String kSecProtocolTypeSSH = "ssh ";

public void setProtocol(String protocol) {
this.protocol = protocol;
}
Expand Down Expand Up @@ -87,14 +100,29 @@ public boolean usesKeychain() {
return this.shouldBeAddedToKeychain;
}

/**
*
* @param protocol
* @return The protocol code as defined in SecKeychain.h
*/
private String getKSecProtocolType(String protocol) {
if(this.protocol.equals(Session.SFTP)) {
return kSecProtocolTypeSSH;
}
if(this.protocol.equals(Session.FTP_TLS)) {
return kSecProtocolTypeFTPS;
}
return kSecProtocolTypeFTP;
}

/**
*
* @return the password fetched from the keychain or null if it was not found
*/
public String getInternetPasswordFromKeychain() {
int pool = NSAutoreleasePool.push();
log.info("Fetching password from Keychain for:" + this.getUsername());
String password = Keychain.instance().getInternetPasswordFromKeychain(this.protocol,
String password = Keychain.instance().getInternetPasswordFromKeychain(this.getKSecProtocolType(this.protocol),
this.hostname, this.getUsername());
NSAutoreleasePool.pop(pool);
return password;
Expand All @@ -106,7 +134,7 @@ public String getInternetPasswordFromKeychain() {
public void addInternetPasswordToKeychain() {
if (this.shouldBeAddedToKeychain && !this.isAnonymousLogin() && this.hasReasonableValues()) {
int pool = NSAutoreleasePool.push();
Keychain.instance().addInternetPasswordToKeychain(this.protocol,
Keychain.instance().addInternetPasswordToKeychain(this.getKSecProtocolType(this.protocol),
this.hostname, this.getUsername(), this.getPassword());
NSAutoreleasePool.pop(pool);
}
Expand All @@ -115,6 +143,7 @@ public void addInternetPasswordToKeychain() {
/**
*
* @return the password fetched from the system keychain or null if it was not found
* @deprecated
*/
public String getPasswordFromKeychain() {
int pool = NSAutoreleasePool.push();
Expand Down

0 comments on commit da2a709

Please sign in to comment.