This repository was archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 155
1073 asymmetric keys #1210
Merged
Merged
1073 asymmetric keys #1210
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3f655ab
1073: property name cleanup to be easier to understand
lhazlewood 85d916b
1073: added RSA and EC signature support
lhazlewood d87874a
Merge branch 'master' into 1073-asymmetric-keys
lhazlewood 52a80ff
fixed file header, removed unused dependency reference
lhazlewood 965b193
1073: fixed artifact id typo
lhazlewood 01038e4
1073: added debug statement
lhazlewood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
api/src/main/java/com/stormpath/sdk/lang/DefaultRuntimeEnvironment.java
This file contains hidden or 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,80 @@ | ||
| /* | ||
| * Copyright 2017 Stormpath, 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. | ||
| */ | ||
| package com.stormpath.sdk.lang; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.security.Provider; | ||
| import java.security.Security; | ||
| import java.util.concurrent.atomic.AtomicBoolean; | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| public final class DefaultRuntimeEnvironment implements RuntimeEnvironment { | ||
|
|
||
| private static final Logger log = LoggerFactory.getLogger(DefaultRuntimeEnvironment.class); | ||
|
|
||
| public static final DefaultRuntimeEnvironment INSTANCE = new DefaultRuntimeEnvironment(); | ||
|
|
||
| private DefaultRuntimeEnvironment() { | ||
| } | ||
|
|
||
| private static final String BC_PROVIDER_CLASS_NAME = "org.bouncycastle.jce.provider.BouncyCastleProvider"; | ||
|
|
||
| private static final AtomicBoolean bcLoaded = new AtomicBoolean(false); | ||
|
|
||
| private static void enableBouncyCastleIfPossible() { | ||
|
|
||
| if (bcLoaded.get()) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| Class clazz = Classes.forName(BC_PROVIDER_CLASS_NAME); | ||
|
|
||
| //check to see if the user has already registered the BC provider: | ||
|
|
||
| Provider[] providers = Security.getProviders(); | ||
|
|
||
| for (Provider provider : providers) { | ||
| if (clazz.isInstance(provider)) { | ||
| bcLoaded.set(true); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| //bc provider not enabled - add it: | ||
| Security.addProvider((Provider) Classes.newInstance(clazz)); | ||
| bcLoaded.set(true); | ||
|
|
||
| } catch (UnknownClassException e) { | ||
| log.debug("Unable to load BouncyCastle. This is an acceptable outcome and this exception " + | ||
| "does not necessarily reflect a problem and can be ignored.", e); | ||
| //not available | ||
| } | ||
| } | ||
|
|
||
| static { | ||
| enableBouncyCastleIfPossible(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isClassAvailable(String fqcn) { | ||
| return Classes.isAvailable(fqcn); | ||
| } | ||
| } | ||
25 changes: 25 additions & 0 deletions
25
api/src/main/java/com/stormpath/sdk/lang/RuntimeEnvironment.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Copyright 2017 Stormpath, 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. | ||
| */ | ||
| package com.stormpath.sdk.lang; | ||
|
|
||
| /** | ||
| * @since 1.3.0 | ||
| */ | ||
| public interface RuntimeEnvironment { | ||
|
|
||
| boolean isClassAvailable(String fqcn); | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe a warn or debug log message? Nature abhors an empty catch block! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a perfectly fine/expected condition, but I suppose a debug statement couldn't hurt, except for waiting for CI for another hour before merge. :/