Skip to content

Commit 664d237

Browse files
committed
PKCS5 support is now part of PKCS8 classes. Also refer to hierynomus/sshj#793.
1 parent da88ab4 commit 664d237

File tree

3 files changed

+40
-48
lines changed

3 files changed

+40
-48
lines changed

manta/src/main/java/ch/cyberduck/core/manta/MantaPublicKeyAuthentication.java

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import net.schmizz.sshj.userauth.keyprovider.KeyFormat;
4949
import net.schmizz.sshj.userauth.keyprovider.KeyProviderUtil;
5050
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
51-
import net.schmizz.sshj.userauth.keyprovider.PKCS5KeyFile;
5251
import net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile;
5352
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile;
5453
import net.schmizz.sshj.userauth.password.PasswordFinder;
@@ -76,39 +75,39 @@ public String authenticate(final Host bookmark, final LoginCallback prompt, fina
7675
log.info(String.format("Reading private key %s with key format %s", identity, format));
7776
}
7877
provider.init(
79-
new InputStreamReader(identity.getInputStream(), StandardCharsets.UTF_8),
80-
new PasswordFinder() {
81-
@Override
82-
public char[] reqPassword(Resource<?> resource) {
83-
if(StringUtils.isEmpty(credentials.getIdentityPassphrase())) {
84-
try {
85-
// Use password prompt
86-
final Credentials input = prompt.prompt(bookmark,
87-
LocaleFactory.localizedString("Private key password protected", "Credentials"),
88-
String.format("%s (%s)",
89-
LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"),
90-
identity.getAbbreviatedPath()),
91-
new LoginOptions()
92-
.icon(bookmark.getProtocol().disk())
93-
.user(false).password(true)
94-
);
95-
credentials.setSaved(input.isSaved());
96-
credentials.setIdentityPassphrase(input.getPassword());
97-
}
98-
catch(LoginCanceledException e) {
99-
// Return null if user cancels
100-
return StringUtils.EMPTY.toCharArray();
78+
new InputStreamReader(identity.getInputStream(), StandardCharsets.UTF_8),
79+
new PasswordFinder() {
80+
@Override
81+
public char[] reqPassword(Resource<?> resource) {
82+
if(StringUtils.isEmpty(credentials.getIdentityPassphrase())) {
83+
try {
84+
// Use password prompt
85+
final Credentials input = prompt.prompt(bookmark,
86+
LocaleFactory.localizedString("Private key password protected", "Credentials"),
87+
String.format("%s (%s)",
88+
LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"),
89+
identity.getAbbreviatedPath()),
90+
new LoginOptions()
91+
.icon(bookmark.getProtocol().disk())
92+
.user(false).password(true)
93+
);
94+
credentials.setSaved(input.isSaved());
95+
credentials.setIdentityPassphrase(input.getPassword());
96+
}
97+
catch(LoginCanceledException e) {
98+
// Return null if user cancels
99+
return StringUtils.EMPTY.toCharArray();
100+
}
101101
}
102+
config.setPassword(credentials.getIdentityPassphrase());
103+
return credentials.getIdentityPassphrase().toCharArray();
102104
}
103-
config.setPassword(credentials.getIdentityPassphrase());
104-
return credentials.getIdentityPassphrase().toCharArray();
105-
}
106105

107-
@Override
108-
public boolean shouldRetry(Resource<?> resource) {
109-
return false;
106+
@Override
107+
public boolean shouldRetry(Resource<?> resource) {
108+
return false;
109+
}
110110
}
111-
}
112111
);
113112
return this.computeFingerprint(provider);
114113
}
@@ -137,8 +136,6 @@ private String computeFingerprint(final FileKeyProvider provider) throws Backgro
137136

138137
private FileKeyProvider buildProvider(final Local identity, final KeyFormat format) throws InteroperabilityException {
139138
switch(format) {
140-
case PKCS5:
141-
return new PKCS5KeyFile.Factory().create();
142139
case PKCS8:
143140
return new PKCS8KeyFile.Factory().create();
144141
case OpenSSH:
@@ -156,8 +153,8 @@ private KeyFormat detectKeyFormat(final Local identity) throws BackgroundExcepti
156153
final KeyFormat format;
157154
try (InputStream is = identity.getInputStream()) {
158155
format = KeyProviderUtil.detectKeyFileFormat(
159-
new InputStreamReader(is, StandardCharsets.UTF_8),
160-
true);
156+
new InputStreamReader(is, StandardCharsets.UTF_8),
157+
true);
161158
}
162159
catch(IOException e) {
163160
throw new DefaultIOExceptionMappingService().map(e);

ssh/src/main/java/ch/cyberduck/core/sftp/auth/SFTPPublicKeyAuthentication.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import net.schmizz.sshj.userauth.keyprovider.KeyFormat;
4444
import net.schmizz.sshj.userauth.keyprovider.KeyProviderUtil;
4545
import net.schmizz.sshj.userauth.keyprovider.OpenSSHKeyFile;
46-
import net.schmizz.sshj.userauth.keyprovider.PKCS5KeyFile;
4746
import net.schmizz.sshj.userauth.keyprovider.PKCS8KeyFile;
4847
import net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile;
4948
import net.schmizz.sshj.userauth.method.AuthPublickey;
@@ -71,14 +70,11 @@ public Boolean authenticate(final Host bookmark, final LoginCallback prompt, fin
7170
final AtomicBoolean canceled = new AtomicBoolean();
7271
try {
7372
final KeyFormat format = KeyProviderUtil.detectKeyFileFormat(
74-
new InputStreamReader(identity.getInputStream(), StandardCharsets.UTF_8), true);
73+
new InputStreamReader(identity.getInputStream(), StandardCharsets.UTF_8), true);
7574
if(log.isInfoEnabled()) {
7675
log.info(String.format("Reading private key %s with key format %s", identity, format));
7776
}
7877
switch(format) {
79-
case PKCS5:
80-
provider = new PKCS5KeyFile.Factory().create();
81-
break;
8278
case PKCS8:
8379
provider = new PKCS8KeyFile.Factory().create();
8480
break;
@@ -101,13 +97,13 @@ public char[] reqPassword(Resource<?> resource) {
10197
try {
10298
// Use password prompt
10399
final Credentials input = prompt.prompt(bookmark,
104-
LocaleFactory.localizedString("Private key password protected", "Credentials"),
105-
String.format("%s (%s)",
106-
LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"),
107-
identity.getAbbreviatedPath()),
108-
new LoginOptions()
109-
.icon(bookmark.getProtocol().disk())
110-
.user(false).password(true)
100+
LocaleFactory.localizedString("Private key password protected", "Credentials"),
101+
String.format("%s (%s)",
102+
LocaleFactory.localizedString("Enter the passphrase for the private key file", "Credentials"),
103+
identity.getAbbreviatedPath()),
104+
new LoginOptions()
105+
.icon(bookmark.getProtocol().disk())
106+
.user(false).password(true)
111107
);
112108
credentials.setSaved(input.isSaved());
113109
credentials.setIdentityPassphrase(input.getPassword());

ssh/src/main/java/ch/cyberduck/core/sftp/openssh/OpenSSHPrivateKeyConfigurator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,13 @@ public Pattern toPattern() {
6464
final KeyFormat format;
6565
try {
6666
format = KeyProviderUtil.detectKeyFileFormat(
67-
new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8), true);
67+
new InputStreamReader(file.getInputStream(), StandardCharsets.UTF_8), true);
6868
}
6969
catch(AccessDeniedException | IOException e) {
7070
log.debug(String.format("Ignore file %s with unknown format. %s", file, e.getMessage()));
7171
continue;
7272
}
7373
switch(format) {
74-
case PKCS5:
7574
case PKCS8:
7675
case OpenSSH:
7776
case OpenSSHv1:

0 commit comments

Comments
 (0)