Combine Network Security Configuration with OkHttp and custom CAs - okhttp

I'm trying to add a network-security-config which restricts connections to servers signed by a set of CAs that I've bundled in the app (actually in a library used by the app).
I have an existing setup that works where the CAs are loaded into the trust store.
Now that I added a network-security-config and try to test it, it doesn't seem to work.
Here is what I tried to do:
AndroidManifest.xml:
<application
...
android:networkSecurityConfig="#xml/network_security_configuration"
...
network-security-configuration.xml:
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false">
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<debug-overrides>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</debug-overrides>
</network-security-config>
What I would expect with this new config is that connections are not allowed to servers that are signed by self-signed CAs such as the ones I have bundled. But when I run the app the connections work fine, so the network-security-configuration does not seem to work...
What I ultimately would like to do is to add my CAs to the trust-anchors:
<certificates src="#raw/my_ca" />
My setup,
App:
Android App Gradle Plugin 7.0
Targeting API 30
Library:
Android App Gradle Plugin 7.0
Targeting API 30
Phone:
Samsung Galaxy S20
Android 11 (=API 30)
Why is the network-security-configuration not applied?

Related

WinUI Registration Free WinRT Component

I followed the following tutorial on how to register a UWP registration free WinRT component https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/ but I continue to receive errors about the component not being registered.
I begin by creating a Propertysheet.props sheet, like in the tutorial:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup />
<ItemGroup />
<ItemGroup>
<Reference Include="C:\Users\User\Solution\x64\Debug\Component\Component.winmd">
<IsWinmdFile>true</IsWinmdFile>
</Reference>
<ReferenceCopyLocationPaths Include="C:\Users\User\Solution\x64\Debug\Component\Component.dll">
<IsWinmdFile>false</IsWinmdFile>
</ReferenceCopyLocationPaths>
<!--<Reference Include="C:\Users\User\Solution\x64\Debug\Component2\Component2.winmd">
<IsWinmdFile>true</IsWinmdFile>
</Reference>
<ReferenceCopyLocationPaths Include="C:\Users\User\Solution\x64\Debug\Component2\Component2.dll">
<IsWinmdFile>false</IsWinmdFile>
</ReferenceCopyLocationPaths>-->
</ItemGroup>
</Project>
When the solution is compiled, the Winmd and the dll for Component are added to the DUALITY.exe folder, but only the Winmd for Component2 has been auto added so I remmed it out for now. I then add the Propertysheet.props to the Application project using the properties manager utility. This disabled the ability to add reference, but it still works as though it has been added. My app.manifest looks like this:
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="Application.app"/>
<application xmlns="urn:schemas-microsoft-com:asm.v3">
<windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness>
</windowsSettings>
</application>
<file name="Component.dll">
<activatableClass
name="Component.SubNamespace.Class"
threadingModel="both"
xmlns="urn:schemas-microsoft-com:winrt.v1" />
</file>
<!--<file name="Component2.dll">
<activatableClass
name="Component.PeregrineX12"
threadingModel="both"
xmlns="urn:schemas-microsoft-com:winrt.v1" />
</file>-->
</assembly>
There were concerns about Namespace and I itterated through a few possibilities. I get an error in my Appmanifest.xml at line 39:
"DEP0700: Registration of the app failed. [0x80080204] error 0xC00CE012: App manifest validation error: The app manifest must be valid as per schema: Line 39, Column 8, Reason: Content for element '{http://schemas.microsoft.com/appx/manifest/foundation/windows10}InProcessServer' is incomplete according to the DTD/Schema. Expecting: {http://schemas.microsoft.com/appx/manifest/foundation/windows10}ActivatableClass."
and the Appmanifest.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap rescap build" xmlns:build="http://schemas.microsoft.com/developer/appx/2015/build">
<Identity Name="837f0535-5d07-4290-983b-a49988c57b12" Publisher="CN=User" Version="1.0.0.0" ProcessorArchitecture="x64" />
<Properties>
<DisplayName>Application</DisplayName>
<PublisherDisplayName>User</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.22000.0" MaxVersionTested="10.0.22000.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<PackageDependency Name="Microsoft.WindowsAppRuntime.1.1" MinVersion="1001.524.1918.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug" MinVersion="14.0.30704.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
<PackageDependency Name="Microsoft.VCLibs.140.00.Debug.UWPDesktop" MinVersion="14.0.30704.0" Publisher="CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" />
</Dependencies>
<Resources>
<Resource Language="EN-US" />
</Resources>
<Applications>
<Application Id="App" Executable="Application.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="Application" Description="DUALITY" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Extensions>
<Extension Category="windows.activatableClass.inProcessServer">
<InProcessServer>
<Path>Component.dll</Path>
</InProcessServer>
</Extension>
</Extensions>
<build:Metadata>
<build:Item Name="cl.exe" Version="19.31.31107.0" />
<build:Item Name="OptimizingToolset" Value="None" />
<build:Item Name="TargetRuntime" Value="Native" />
<build:Item Name="Microsoft.UI.Xaml.Markup.Compiler.dll" Version="1.0.0.0" />
<build:Item Name="Microsoft.UniversalCRT.Debug" Version="10.0.22000.0" />
<build:Item Name="makepri.exe" Version="10.0.22621.1 (WinBuild.160101.0800)" />
</build:Metadata>
</Package>
At this point, this was the first time an attempt was made by the framework to register the dll. This is all of the information I have collected from documentation, at this time. As can be seen ActivatableClass was not added and I'm pretty sure it should have been.
I'm going to re-summarize here, based on what I have come to, going through more of the documentation.
When you create a WinUI App, you can create a Packaged app with a packaging project or without. Here was my first mistake. The second project template is still a Packaged App and not an Unpackaged App. So keep that in mind while choosing your approach. The above tutorial says that the tutorial is specific to Unpackaged Apps, but it is applicable to both Packaged and Unpackaged Apps.
The tutorial describes how to consume WinRT Components calling it Registration Free. But WinRT is a Registration Free framework. Calling it Registration Free was misleading. Registration Free simply meant that it uses a manifest and doesn't mean you can gain access to the component without registering it with the App. Unless late binding (calling plugins), you will have to follow the Registration Free in application registration.
When making a Packaged App I needed to include the NuGet package Microsoft.VCRTForwarders.140. The tutorial uses app.manifest to declare activatableClasses. This is a shortcut, and really, you need to use the Package.appxmanifest to acquire full framework functionality; like declaring Proxy-Stub Servers for Interfaces. I use the Propertysheet.props to include the winmds and move the dll's into the exe folder, instead of just making a reference to the winmd and manually copying the dll's.
Here I learned I wasn't actually making an Unpackaged App. To make an Unpackaged App, first I had to make a Packaged App with no packaging project. Then, WindowPackageType had to be set to None and AppxPackage to false in the project file. Package.appxmanifest had to be removed from the project. I no longer needed the NuGet. Instead I needed to install the required framework bits, and load the Bootstrapper. This enabled connectivity and started the winrt framework in the Unpackaged environment. When not late binding, I included the winmds and moved my dll's into the executable folder using the Propertysheet.props. In this way I was able to use winrt get_activation_factory to make Runtime Classes in WinUI Components. There was no single document that covered this.
I found the easiest way to late bind WinRT components was--in an unpackaged or packaged app--was to load the dll using WINRT_IMPL_LoadLibraryW from base.h and call the GetActivationFactory directly using WINRT_IMPL_GetProcAddress. The only problem with this was that the Xaml framework didn't just extend into the WinUI Component. Xaml content was unable to load in the loaded component dll. I believe there is a way to add Xaml functionality, but it looks like it mixes with legacy WRL code and Xaml islands.
My solution to this last problem was to start another WinUI process. I Loaded a sub App from an App as a driver for the code behind. Other than to have a call up application, I don't see why I'd personally use controls defined in WinUI component dll's, and will simply use the main processes to drive behind UI logic in modular WinRT dll's. Especially with my Desktop Application already being so modular. Need new UI functionality, make a new one off of a template. For my purposes this makes the most sense. WinUI, WinRT, and Windows::Foundation all work without Xaml. I even passed a SwapChainPanel to a WinUI Component dll to make late binding DirectX12 graphics pipelines, so we're doing good.

Getting Unknown error in charles during inspecting api websocket of an android app

Hey Some Days ago am working with charles nd its working properly but now i am unable to use it, it shows me unknown. I tried with 2 android (android pie) & 1 android emulator (android lollipop including root). I tried with all network security config below:
1) Given on Charles Official website
<network-security-config>
<debug-overrides>
<trust-anchors>
<!-- Trust user added CAs while debuggable only -->
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
2) From other sources
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system" />
</trust-anchors>
</base-config>
<debug-overrides>
<trust-anchors>
<certificates src="user" />
</trust-anchors>
</debug-overrides>
</network-security-config>
I was using 2nd network security config when its working properly. Is there any solution or alternative method to inspect the responses and websockets inside the app.

How to pass args to a UWP Application with EntryPoint="Windows.FullTrustApplication" in AppxManifest.xml

I am trying to set up an AppxManifest.xml to launch a Win32 application as a full trust application. Using the snippet below, I am able to Add-AppxPackage -Register AppxManifest.xml and then use Debug > Other Debugging Tools > Debug Installed Application to debug the application in Visual Studio 2017.
However, I want to pass some arguments to the application when launching it. How can I acomplish this? I don't mind listing them in the AppxManifest.xml if that is easiest, I just need to know how.
...
<Applications>
<Application Id="App" Executable="SomeExecutable.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="Wrap" Description="Wrap" BackgroundColor="transparent" Square150x150Logo="Assets\Square150x150Logo.png" Square44x44Logo="Assets\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png" />
</uap:VisualElements>
</Application>
</Applications>
...
Protocol associations is what you look for:
Protocol associations can enable other programs and system components
to interoperate with your packaged app. When your packaged application
is started by using a protocol, you can specify specific parameters to
pass to its activation event arguments so it can behave accordingly.
Parameters are supported only for packaged, full-trust apps.
<Package
xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
IgnorableNamespaces="uap3, desktop">
<Applications>
<Application>
<Extensions>
<uap3:Extension
Category="windows.protocol">
<uap3:Protocol
Name="myapp-cmd"
Parameters="/p " />
</uap3:Extension>
</Extensions>
</Application>
</Applications>
</Package>

phonegap build for kitkat

I have made a phonegap app which works on all other devices except my tablet which runs KitKat(the app installs but displays a blank white screen instead of the content). I checked to see if this was an issue with it being a tablet but it seems to be the android version as the exact same app build works on another tablet running android lollipop...
This is the code in my config file, is there something else I need to add or something I should remove so that it will run correctly on the KitKat tablet?
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld"
version="1.0.0"
xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
xmlns:android = "http://schemas.android.com/apk/res/android">
<config-file platform="android" parent="/manifest" mode="merge">
<supports-screens
android:xlargeScreens="true"
android:largeScreens="true"
android:smallScreens="true"
android:requiresSmallestWidthDp="600"
/>
<uses-sdk android:minSdkVersion="19"
android:targetSdkVersion="19"/>
</config-file>
<name>My App</name>
<description>
Tablet App.
</description>
<content src="index.html"/>
<preference name="target-device" value="universal" />
<preference name="android-minSdkVersion" value="19" />
<preference name="android-targetSdkVersion" value="19"/>
<preference name="orientation" value="landscape" />
<access origin="*"/>
</widget>
I am not using an plugins, and am using build.phonegap to build my app.
Thanks in advance
I managed to get the google chrome remote device debugger working and it was an error in my code: I had used let instead of var and KitKat does not recognize let.
I changed all my let declarations to var and now it works perfectly.

Glassfish and Spring Boot: .war re-deployment failed

I am trying to deploy an application build from https://github.com/spring-guides/gs-convert-jar-to-war to local glassfish4. And it delpoys well for the first time (if I can call some exceptions from the framework good behaviour). At least, I can open the project's index page in browser.
But if I try to undeploy it and re-deploy, or just overwrite .war file in autodeploy directory, deployment fails. And nothing seems to be added to glassfish log file.
The projects I published from eclipse using some its mechanisms deployed and re-deployed successfully.
Here is the log with related contents:
http://pastebin.com/zSeMw5tC
What can be the problem?
I did some experiments with Glassfish a while ago. The CDI implementation is really broken IMO (it shouldn't load classes to scan them for annotations), but the apps I tried worked on GF 4 if there is a WEB-INF/classes/META-INF/beans.xml containing
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee http://docs.jboss.org/cdi/beans_1_0.xsd"
bean-discovery-mode="none">
<scan>
<exclude name="org.springframework.**" />
<exclude name="org.apache.**" />
<exclude name="com.google.**" />
</scan>
</beans>
Nothing I did ever worked in GF 3 (older CDI spec and no way to exclude things I think).

Resources