-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0ccbe6a
Showing
16 changed files
with
534 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Using the SSL Certificates Chain API web service | ||
|
||
[SSL Certificates Chain API](https://threatintelligenceplatform.com/threat-intelligence-apis/ssl-certificates-chain-api) | ||
provides you an opportunity to get a chain of SSL certificates for any active | ||
domain name. | ||
|
||
Here you'll find examples of querying the API implemented in multiple | ||
languages. | ||
|
||
You'll need a | ||
[Threat Intelligence Platform account](https://threatintelligenceplatform.com/signup) to | ||
authenticate. | ||
|
||
Please, refer to the | ||
[SSL Certificates Chain API Guide](https://threatintelligenceplatform.com/threat-intelligence-api-docs/ssl-certificates-chain-api) | ||
for info on input parameters, request/response formats, authentication | ||
instructions and more. |
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,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.threatintelligenceplatform</groupId> | ||
<artifactId>ssl-certificates-chain-api-sample</artifactId> | ||
<version>0.0.1</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>ssl-certificates-chain-api-sample</name> | ||
<description>Example of using the SSL Certificates Chain API</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.code.gson</groupId> | ||
<artifactId>gson</artifactId> | ||
<version>2.8.2</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.6.0</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>java</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<mainClass>SslCertificatesChainApi</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
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,81 @@ | ||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.net.URLEncoder; | ||
|
||
import javax.net.ssl.HttpsURLConnection; | ||
|
||
import com.google.gson.*; | ||
|
||
public class SslCertificatesChainApi { | ||
private static final String BASE_URL = | ||
"https://api.threatintelligenceplatform.com/v1/sslCertificatesChain"; | ||
|
||
private String apiKey; | ||
|
||
public static void main(String[] args) | ||
{ | ||
SslCertificatesChainApi api = new SslCertificatesChainApi(); | ||
api.setApiKey("Your SSL Certificates Chain API key"); | ||
|
||
try { | ||
System.out.println(api.sendGet("threatintelligenceplatform.com")); | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
public String sendGet(String domain) throws Exception | ||
{ | ||
String userAgent = "Mozilla/5.0"; | ||
String url = this.buildUrl(domain); | ||
|
||
URL obj = new URL(url); | ||
|
||
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); | ||
|
||
con.setRequestMethod("GET"); | ||
con.setRequestProperty("User-Agent", userAgent); | ||
|
||
BufferedReader in = new BufferedReader( | ||
new InputStreamReader(con.getInputStream())); | ||
|
||
String inputLine; | ||
StringBuilder response = new StringBuilder(); | ||
|
||
while ((inputLine = in.readLine()) != null) { | ||
response.append(inputLine); | ||
} | ||
in.close(); | ||
|
||
return prettyJson(response.toString()); | ||
} | ||
|
||
public void setApiKey(String apiKey) | ||
{ | ||
this.apiKey = apiKey; | ||
} | ||
|
||
private String buildUrl(String domain) throws IOException | ||
{ | ||
return SslCertificatesChainApi.BASE_URL | ||
+ "?apiKey=" + URLEncoder.encode(getApiKey(), "UTF-8") | ||
+ "&domainName=" + URLEncoder.encode(domain, "UTF-8"); | ||
} | ||
|
||
private String getApiKey() | ||
{ | ||
return this.apiKey; | ||
} | ||
|
||
private String prettyJson(String jsonString) | ||
{ | ||
Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
|
||
JsonParser jp = new JsonParser(); | ||
JsonElement je = jp.parse(jsonString); | ||
|
||
return gson.toJson(je); | ||
} | ||
} |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.2" level="project" /> | ||
</component> | ||
</module> |
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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>SSL Certificates Chain API Sample</title> | ||
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> | ||
<script type="text/javascript"> | ||
|
||
var url = "https://api.threatintelligenceplatform.com/v1/sslCertificatesChain"; | ||
|
||
var apiKey = "Your SSL Certificates Chain API key"; | ||
var domain = "threatintelligenceplatform.com"; | ||
|
||
$(function() { | ||
$.ajax( | ||
{ | ||
url: url, | ||
dataType: "json", | ||
data: { | ||
apiKey: apiKey, | ||
domainName: domain | ||
}, | ||
success: function(response) { | ||
$("#json").append(JSON.stringify(response, null, 2)); | ||
}, | ||
error: function(e) { | ||
$("#error").append(e.responseText); | ||
} | ||
} | ||
); | ||
}); | ||
|
||
</script> | ||
</head> | ||
|
||
<body> | ||
<div id="error"></div> | ||
<pre id="json"></pre> | ||
</body> | ||
|
||
</html> |
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,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.0.0 | ||
MinimumVisualStudioVersion = 10.0.0.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SslCertificatesChainApiSample", "SslCertificatesChainApiSample/SslCertificatesChainApiSample.csproj", "{ADDD9223-A632-4968-BC23-50A20EAE935B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{ADDD9223-A632-4968-BC23-50A20EAE935B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{ADDD9223-A632-4968-BC23-50A20EAE935B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{ADDD9223-A632-4968-BC23-50A20EAE935B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{ADDD9223-A632-4968-BC23-50A20EAE935B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
36 changes: 36 additions & 0 deletions
36
net/SslCertificatesChainApiSample/Properties/AssemblyInfo.cs
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,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("SslCertificatesChainApiSample")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("SslCertificatesChainApiSample")] | ||
[assembly: AssemblyCopyright("Copyright © 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("ADDD9223-A632-4968-BC23-50A20EAE935B")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
63 changes: 63 additions & 0 deletions
63
net/SslCertificatesChainApiSample/SslCertificatesChainApiSample.cs
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,63 @@ | ||
using System; | ||
using System.Net; | ||
|
||
using Newtonsoft.Json; | ||
|
||
namespace SslCertificatesChainApiSample | ||
{ | ||
internal class SslCertificatesChainApiSample | ||
{ | ||
private static void Main() | ||
{ | ||
var client = new SslCertificatesChainApiClient | ||
{ | ||
ApiKey = "Your SSL Certificates Chain API key" | ||
}; | ||
|
||
const string domain = "threatintelligenceplatform.com"; | ||
|
||
// Download JSON | ||
var result = client.SendGet(domain); | ||
|
||
// Print a nice informative string | ||
PrintResponse(result); | ||
} | ||
|
||
private static void PrintResponse(string response) | ||
{ | ||
dynamic responseObject = JsonConvert.DeserializeObject(response); | ||
|
||
if (responseObject != null) | ||
{ | ||
Console.Write("Chain length: " + responseObject.Count); | ||
Console.WriteLine("\n--------------------------------"); | ||
return; | ||
} | ||
|
||
Console.WriteLine(); | ||
} | ||
} | ||
|
||
public class SslCertificatesChainApiClient | ||
{ | ||
public string ApiKey { private get; set; } | ||
|
||
private const string Url = | ||
"https://api.threatintelligenceplatform.com/v1/sslCertificatesChain"; | ||
|
||
public string SendGet(string domain) | ||
{ | ||
var requestParams = "?domainName=" + Uri.EscapeDataString(domain) | ||
+ "&apiKey=" + Uri.EscapeDataString(ApiKey); | ||
|
||
var fullUrl = Url + requestParams; | ||
|
||
Console.Write("Sending request to: " + fullUrl + "\n"); | ||
|
||
// Download JSON into a string | ||
var result = new WebClient().DownloadString(fullUrl); | ||
|
||
return result; | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
net/SslCertificatesChainApiSample/SslCertificatesChainApiSample.csproj
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,62 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{ADDD9223-A632-4968-BC23-50A20EAE935B}</ProjectGuid> | ||
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>SslCertificatesChainApiSample</RootNamespace> | ||
<AssemblyName>SslCertificatesChainApiSample</AssemblyName> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> | ||
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="SslCertificatesChainApiSample.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net45" /> | ||
</packages> |
Oops, something went wrong.