Repository navigation
Closed
Milestone
Description
Hi.
Here's a let's-encrypt certificate that decrypted just fine in 3.1.2, but after upgrading to 5.0.0 preview 1, started exploding in linux only.
(It's valid - but it's a dev cert in a dev environment, so no big deal).
var certraw = new byte[] { 48, 128, 2, 1, 3, 48, 128, 6, 9, 42, 134, 72, 134, 247, 13, 1, 7, 1, 160, 128, 36, 128, 4, 130, 3, 232, 48, 128, 48, 128, 6, 9, 42, 134, 72, 134, 247, 13, 1, 7, 1, 160, 128, 36, 128, 4, 129, 241, 48, 129, 238, 48, 129, 235, 6, 11, 42, 134, 72, 134, 247, 13, 1, 12, 10, 1, 2, 160, 126, 48, 124, 48, 40, 6, 10, 42, 134, 72, 134, 247, 13, 1, 12, 1, 3, 48, 26, 4, 20, 134, 214, 18, 255, 79, 105, 5, 182, 86, 4, 230, 209, 59, 12, 113, 121, 42, 161, 220, 10, 2, 2, 4, 0, 4, 80, 9, 185, 106, 204, 50, 152, 203, 101, 127, 148, 106, 231, 154, 11, 48, 211, 6, 30, 4, 35, 188, 213, 167, 215, 72, 202, 35, 170, 240, 190, 201, 123, 218, 25, 150, 187, 235, 10, 165, 16, 151, 154, 82, 174, 218, 7, 128, 133, 159, 11, 9, 17, 232, 73, 146, 254, 248, 159, 67, 124, 215, 254, 97, 149, 155, 174, 154, 136, 166, 101, 15, 103, 90, 220, 0, 3, 205, 40, 132, 104, 49, 92, 48, 35, 6, 9, 42, 134, 72, 134, 247, 13, 1, 9, 21, 49, 22, 4, 20, 203, 132, 68, 40, 26, 51, 35, 157, 202, 106, 233, 155, 100, 142, 177, 121, 163, 79, 187, 101, 48, 53, 6, 9, 42, 134, 72, 134, 247, 13, 1, 9, 20, 49, 40, 30, 38, 0, 97, 0, 112, 0, 112, 0, 46, 0, 100, 0, 101, 0, 118, 0, 46, 0, 115, 0, 121, 0, 109, 0, 101, 0, 116, 0, 114, 0, 105, 0, 97, 0, 46, 0, 105, 0, 111, 0, 0, 0, 0, 0, 0, 48, 128, 6, 9, 42, 134, 72, 134, 247, 13, 1, 7, 6, 160, 128, 48, 128, 2, 1, 0, 48, 128, 6, 9, 42, 134, 72, 134, 247, 13, 1, 7, 1, 48, 40, 6, 10, 42, 134, 72, 134, 247, 13, 1, 12, 1, 6, 48, 26, 4, 20, 228, 201, 157, 17, 238, 55, 46, 230, 158, 73, 10, 226, 69, 84, 209, 207, 36, 92, 92, 133, 2, 2, 4, 0, 160, 128, 4, 130, 3, 232, 173, 163, 210, 157, 171, 152, 166, 41, 89, 181, 136, 82, 249, 175, 170, 92, 136, 103, 45, 33, 134, 146, 251, 139, 34, 166, 165, 209, 151, 90, 205, 188, 219, 62, 183, 178, 236, 23, 142, 188, 209, 116, 38, 214, 181, 11, 69, 248, 182, 173, 3, 207, 230, 244, 13, 184, 150, 49, 61, 213, 198, 20, 41, 124, 247, 19, 163, 144, 99, 221, 219, 249, 36, 17, 137, 64, 121, 195, 122, 220, 225, 240, 36, 150, 156, 121, 85, 212, 203, 169, 179, 116, 77, 159, 65, 245, 200, 86, 29, 212, 219, 21, 219, 156, 207, 50, 132, 254, 137, 8, 39, 234, 191, 50, 43, 212, 158, 125, 232, 150, 133, 252, 224, 84, 130, 69, 89, 4, 129, 152, 150, 144, 84, 84, 92, 229, 209, 241, 17, 125, 221, 70, 241, 150, 62, 235, 214, 192, 190, 69, 218, 103, 139, 10, 171, 8, 231, 218, 12, 8, 112, 173, 6, 99, 48, 230, 113, 82, 97, 189, 73, 51, 173, 113, 177, 134, 179, 120, 156, 62, 179, 128, 34, 96, 188, 241, 115, 20, 204, 211, 0, 180, 179, 191, 124, 109, 104, 62, 129, 27, 121, 190, 26, 198, 126, 254, 111, 13, 90, 64, 120, 149, 113, 125, 163, 96, 173, 2, 20, 101, 183, 52, 55, 99, 68, 254, 150, 0, 153, 217, 149, 12, 124, 84, 191, 240, 154, 52, 235, 159, 248, 35, 236, 7, 5, 76, 73, 228, 125, 179, 121, 218, 60, 243, 241, 13, 229, 251, 64, 83, 125, 204, 187, 224, 126, 165, 137, 245, 93, 191, 157, 114, 12, 203, 78, 40, 81, 119, 93, 102, 139, 22, 165, 94, 194, 149, 172, 40, 128, 23, 6, 98, 210, 60, 62, 181, 128, 189, 184, 130, 224, 7, 149, 219, 210, 2, 75, 160, 88, 13, 27, 140, 242, 44, 64, 32, 89, 158, 120, 94, 80, 108, 37, 251, 108, 96, 207, 244, 156, 26, 31, 137, 173, 127, 179, 229, 97, 233, 234, 203, 238, 106, 130, 46, 225, 149, 94, 200, 105, 67, 217, 80, 101, 233, 30, 154, 111, 38, 86, 118, 134, 78, 246, 33, 156, 214, 38, 85, 131, 169, 147, 165, 200, 236, 129, 233, 143, 146, 105, 134, 231, 205, 209, 174, 211, 184, 25, 96, 74, 205, 0, 51, 188, 135, 213, 103, 9, 203, 68, 179, 114, 232, 14, 37, 229, 6, 44, 12, 49, 223, 242, 204, 192, 149, 163, 173, 122, 227, 146, 29, 190, 34, 200, 69, 235, 195, 95, 15, 197, 205, 244, 171, 17, 193, 82, 108, 233, 2, 243, 52, 136, 135, 215, 62, 23, 116, 42, 33, 238, 58, 103, 146, 203, 80, 26, 73, 59, 16, 29, 234, 128, 79, 161, 34, 4, 219, 8, 147, 116, 0, 80, 8, 30, 115, 101, 12, 138, 215, 122, 146, 26, 62, 15, 179, 15, 71, 173, 200, 152, 87, 173, 65, 57, 206, 224, 92, 32, 216, 136, 225, 72, 67, 76, 230, 10, 28, 191, 209, 20, 22, 172, 254, 172, 32, 168, 132, 239, 21, 111, 18, 215, 160, 165, 70, 134, 39, 62, 77, 10, 81, 190, 79, 18, 248, 234, 196, 96, 57, 118, 102, 115, 94, 140, 255, 182, 198, 225, 116, 101, 246, 1, 69, 216, 148, 205, 182, 55, 22, 171, 180, 194, 209, 24, 236, 30, 26, 136, 32, 82, 74, 197, 105, 8, 76, 155, 215, 170, 64, 206, 246, 45, 12, 71, 180, 133, 36, 98, 39, 147, 111, 94, 210, 219, 16, 224, 28, 26, 60, 181, 252, 120, 193, 67, 99, 195, 235, 225, 102, 99, 161, 37, 78, 65, 64, 231, 176, 244, 61, 105, 252, 207, 10, 91, 136, 41, 188, 100, 247, 144, 74, 103, 176, 233, 132, 168, 85, 249, 12, 6, 12, 199, 189, 101, 166, 196, 18, 86, 10, 187, 233, 4, 130, 3, 232, 4, 49, 125, 132, 179, 118, 218, 230, 163, 74, 159, 81, 153, 153, 13, 165, 246, 205, 32, 248, 93, 146, 52, 71, 252, 170, 49, 161, 233, 250, 131, 216, 73, 67, 147, 114, 254, 21, 171, 245, 194, 11, 152, 17, 226, 111, 124, 8, 65, 80, 240, 32, 129, 120, 244, 184, 79, 5, 232, 248, 1, 238, 3, 101, 214, 110, 57, 211, 29, 6, 172, 249, 125, 75, 5, 137, 235, 209, 82, 136, 86, 57, 77, 219, 11, 226, 236, 53, 110, 100, 217, 221, 247, 24, 146, 216, 4, 106, 64, 238, 202, 66, 246, 185, 100, 12, 147, 247, 11, 38, 158, 246, 221, 45, 102, 88, 251, 74, 189, 242, 178, 20, 153, 164, 23, 159, 48, 204, 165, 27, 74, 173, 175, 140, 118, 136, 19, 238, 230, 147, 90, 230, 203, 38, 134, 88, 3, 202, 219, 224, 85, 158, 195, 95, 15, 141, 87, 90, 23, 5, 142, 188, 56, 52, 59, 124, 180, 196, 64, 99, 198, 78, 97, 139, 3, 123, 134, 54, 89, 138, 185, 91, 66, 225, 229, 58, 55, 188, 99, 55, 121, 214, 124, 78, 84, 114, 238, 192, 87, 71, 75, 124, 234, 150, 234, 23, 241, 150, 248, 125, 236, 109, 192, 163, 109, 135, 170, 131, 36, 44, 108, 118, 106, 155, 75, 8, 136, 246, 9, 235, 60, 233, 253, 35, 13, 164, 145, 249, 121, 118, 218, 189, 211, 97, 46, 245, 74, 167, 213, 194, 100, 220, 189, 28, 188, 200, 49, 195, 136, 219, 112, 137, 104, 188, 41, 79, 226, 34, 38, 130, 225, 99, 116, 20, 119, 223, 141, 161, 85, 108, 179, 154, 175, 86, 181, 25, 83, 126, 245, 24, 32, 54, 165, 158, 14, 105, 50, 17, 59, 45, 42, 184, 209, 110, 112, 196, 52, 233, 254, 200, 58, 106, 93, 191, 179, 99, 59, 69, 189, 30, 94, 132, 38, 219, 207, 21, 187, 43, 78, 184, 237, 85, 20, 250, 247, 252, 76, 17, 33, 161, 80, 253, 238, 210, 27, 114, 15, 199, 134, 244, 4, 130, 3, 232, 38, 8, 230, 117, 52, 250, 201, 37, 105, 191, 66, 36, 157, 123, 73, 109, 228, 145, 135, 62, 223, 207, 27, 176, 163, 60, 91, 173, 78, 49, 190, 83, 241, 153, 124, 170, 72, 184, 80, 184, 234, 15, 118, 72, 255, 119, 97, 60, 87, 91, 161, 187, 21, 202, 72, 216, 117, 166, 124, 46, 6, 34, 219, 110, 211, 124, 6, 225, 225, 83, 68, 216, 72, 14, 205, 120, 89, 126, 89, 131, 220, 104, 242, 202, 31, 7, 42, 151, 10, 231, 93, 155, 244, 76, 156, 37, 32, 86, 126, 238, 5, 254, 130, 181, 179, 246, 29, 47, 7, 145, 99, 30, 27, 90, 6, 53, 145, 197, 93, 71, 135, 60, 247, 33, 156, 210, 169, 51, 157, 30, 83, 120, 102, 187, 185, 207, 11, 172, 9, 84, 129, 42, 129, 197, 215, 252, 191, 127, 29, 160, 1, 167, 23, 29, 209, 59, 27, 194, 103, 89, 245, 154, 49, 251, 111, 251, 47, 63, 216, 233, 35, 197, 127, 157, 246, 197, 57, 18, 137, 53, 50, 77, 7, 118, 111, 50, 26, 90, 21, 93, 242, 183, 82, 138, 112, 187, 142, 118, 153, 101, 197, 124, 221, 227, 184, 195, 239, 143, 132, 211, 156, 125, 62, 120, 78, 142, 4, 74, 178, 7, 195, 71, 242, 201, 21, 127, 242, 161, 124, 193, 231, 41, 157, 11, 48, 204, 113, 43, 190, 159, 145, 244, 246, 228, 129, 207, 135, 86, 116, 216, 118, 253, 184, 205, 124, 42, 31, 176, 216, 42, 150, 179, 9, 153, 102, 2, 255, 200, 22, 149, 82, 205, 203, 185, 178, 116, 54, 6, 203, 74, 80, 17, 36, 4, 145, 29, 52, 97, 1, 132, 239, 59, 29, 30, 12, 27, 233, 78, 194, 175, 80, 207, 210, 44, 178, 229, 61, 3, 105, 141, 173, 10, 103, 185, 190, 120, 44, 18, 139, 33, 127, 152, 197, 226, 61, 28, 134, 252, 196, 132, 220, 81, 116, 17, 164, 94, 211, 2, 175, 121, 214, 92, 144, 77, 138, 55, 6, 18, 124, 124, 31, 143, 126, 232, 242, 255, 96, 191, 197, 83, 221, 82, 203, 127, 189, 212, 50, 132, 3, 114, 106, 168, 119, 172, 164, 104, 101, 3, 101, 73, 137, 74, 50, 201, 243, 254, 234, 209, 231, 217, 69, 238, 62, 61, 176, 194, 129, 235, 70, 90, 40, 79, 93, 84, 222, 160, 30, 199, 0, 67, 9, 52, 131, 229, 38, 8, 215, 211, 141, 123, 33, 170, 51, 194, 95, 187, 25, 152, 3, 1, 19, 122, 155, 90, 223, 151, 58, 77, 252, 119, 208, 172, 242, 19, 123, 239, 199, 6, 94, 15, 79, 122, 95, 229, 220, 112, 220, 109, 0, 178, 243, 167, 14, 171, 143, 35, 158, 209, 138, 68, 28, 177, 96, 87, 194, 0, 155, 100, 139, 208, 92, 170, 246, 18, 230, 211, 51, 194, 17, 78, 100, 7, 42, 146, 160, 221, 210, 60, 144, 52, 73, 23, 79, 188, 14, 49, 19, 175, 238, 173, 171, 244, 129, 114, 110, 21, 15, 76, 64, 22, 153, 42, 235, 244, 150, 4, 175, 58, 21, 36, 254, 251, 42, 204, 206, 177, 163, 34, 214, 65, 164, 33, 21, 74, 89, 135, 38, 173, 59, 27, 203, 118, 215, 178, 234, 86, 228, 78, 117, 219, 2, 181, 207, 163, 175, 6, 6, 68, 148, 151, 29, 213, 105, 247, 84, 179, 198, 144, 146, 173, 43, 210, 33, 128, 7, 76, 2, 99, 67, 54, 149, 85, 130, 19, 5, 183, 76, 188, 72, 65, 27, 160, 228, 216, 101, 78, 192, 59, 62, 245, 169, 231, 176, 235, 7, 107, 227, 222, 131, 192, 184, 10, 244, 109, 243, 170, 193, 212, 103, 96, 194, 188, 133, 14, 184, 194, 180, 212, 75, 235, 253, 224, 3, 54, 60, 23, 4, 130, 3, 170, 111, 58, 168, 127, 136, 222, 76, 213, 74, 145, 61, 101, 121, 74, 13, 137, 246, 110, 131, 225, 49, 204, 97, 65, 152, 1, 79, 116, 206, 243, 8, 111, 232, 181, 112, 225, 5, 65, 88, 232, 47, 197, 92, 119, 125, 123, 244, 56, 14, 196, 79, 214, 63, 70, 196, 188, 216, 243, 196, 93, 229, 44, 58, 53, 158, 95, 209, 115, 199, 231, 167, 162, 103, 89, 67, 108, 149, 34, 4, 128, 32, 165, 57, 135, 158, 195, 144, 8, 144, 166, 55, 87, 153, 44, 129, 77, 244, 103, 172, 43, 153, 207, 222, 252, 142, 142, 161, 200, 139, 65, 229, 172, 241, 126, 152, 74, 89, 172, 106, 9, 185, 125, 118, 135, 182, 215, 197, 73, 154, 105, 54, 16, 175, 89, 196, 178, 236, 30, 23, 45, 104, 160, 93, 32, 51, 113, 117, 248, 160, 50, 134, 97, 125, 44, 197, 55, 69, 150, 37, 29, 157, 123, 137, 164, 90, 141, 16, 137, 48, 16, 164, 99, 209, 210, 10, 237, 182, 29, 141, 106, 189, 48, 202, 239, 15, 58, 230, 173, 113, 253, 38, 121, 129, 194, 162, 122, 155, 191, 140, 64, 165, 65, 153, 148, 129, 185, 194, 107, 239, 55, 76, 191, 249, 31, 254, 164, 6, 140, 252, 231, 156, 227, 35, 52, 0, 233, 206, 132, 140, 169, 200, 235, 91, 109, 98, 98, 210, 186, 108, 25, 4, 60, 116, 78, 39, 67, 93, 245, 145, 11, 88, 182, 182, 49, 161, 174, 107, 197, 159, 11, 145, 26, 42, 93, 54, 249, 246, 120, 166, 220, 126, 245, 152, 132, 255, 201, 253, 142, 103, 162, 156, 199, 133, 53, 116, 58, 201, 176, 1, 159, 128, 41, 229, 227, 16, 225, 167, 247, 61, 144, 140, 233, 254, 99, 179, 200, 119, 149, 101, 70, 150, 134, 36, 41, 216, 126, 86, 152, 99, 138, 18, 172, 247, 240, 243, 209, 229, 121, 63, 55, 93, 246, 172, 157, 225, 196, 40, 108, 190, 212, 81, 2, 115, 46, 97, 74, 200, 215, 226, 202, 171, 42, 189, 156, 4, 130, 2, 56, 46, 49, 145, 173, 195, 210, 43, 222, 239, 121, 69, 210, 205, 50, 121, 185, 204, 200, 226, 255, 203, 243, 139, 192, 65, 19, 198, 41, 188, 211, 245, 170, 172, 122, 132, 247, 251, 188, 18, 195, 148, 229, 24, 247, 7, 255, 64, 144, 249, 232, 120, 195, 15, 59, 134, 225, 107, 164, 199, 16, 105, 137, 255, 249, 101, 237, 90, 13, 151, 207, 111, 26, 2, 76, 40, 119, 93, 184, 91, 8, 180, 157, 247, 56, 9, 13, 238, 88, 14, 234, 211, 12, 36, 68, 205, 172, 17, 137, 209, 8, 1, 188, 12, 23, 159, 126, 9, 223, 23, 50, 177, 40, 101, 117, 220, 250, 243, 171, 189, 247, 108, 6, 242, 173, 217, 17, 187, 178, 22, 137, 220, 255, 237, 253, 128, 145, 39, 185, 5, 54, 70, 152, 143, 80, 31, 211, 248, 51, 2, 86, 20, 0, 172, 21, 234, 177, 0, 157, 237, 92, 85, 154, 78, 37, 228, 210, 136, 99, 176, 213, 135, 167, 159, 204, 180, 88, 98, 186, 90, 124, 228, 18, 173, 197, 157, 154, 47, 173, 109, 117, 212, 86, 106, 204, 214, 178, 73, 144, 86, 227, 2, 18, 213, 36, 69, 124, 77, 195, 201, 165, 111, 207, 127, 30, 198, 27, 97, 120, 229, 165, 38, 40, 131, 147, 157, 104, 160, 192, 104, 145, 0, 199, 156, 133, 139, 40, 50, 172, 100, 138, 24, 182, 237, 90, 143, 94, 248, 79, 129, 156, 152, 127, 119, 11, 37, 103, 66, 210, 65, 147, 100, 64, 34, 117, 153, 243, 89, 176, 248, 47, 207, 114, 149, 148, 226, 106, 196, 197, 23, 243, 150, 80, 131, 134, 174, 21, 18, 53, 90, 63, 218, 182, 184, 223, 54, 64, 61, 60, 32, 163, 136, 0, 58, 87, 39, 24, 65, 190, 181, 203, 4, 8, 110, 156, 136, 216, 204, 31, 239, 242, 53, 152, 163, 12, 209, 204, 8, 61, 145, 157, 191, 139, 139, 126, 77, 86, 76, 156, 241, 102, 51, 26, 32, 83, 228, 70, 128, 139, 246, 118, 206, 196, 58, 6, 53, 148, 6, 123, 192, 136, 189, 158, 155, 73, 53, 131, 248, 204, 125, 226, 93, 212, 187, 232, 42, 196, 0, 81, 161, 158, 154, 134, 191, 15, 208, 103, 138, 247, 121, 189, 91, 55, 133, 13, 234, 138, 135, 162, 25, 168, 1, 136, 213, 208, 13, 23, 141, 238, 121, 64, 199, 163, 179, 235, 230, 149, 146, 129, 192, 109, 241, 225, 234, 90, 250, 57, 143, 124, 158, 173, 202, 70, 33, 129, 191, 193, 90, 254, 56, 85, 83, 117, 147, 3, 82, 122, 154, 79, 83, 151, 113, 22, 178, 236, 234, 187, 242, 87, 143, 32, 160, 239, 139, 179, 225, 144, 192, 140, 32, 63, 54, 58, 231, 233, 65, 201, 16, 233, 198, 34, 192, 3, 192, 231, 165, 69, 246, 138, 164, 195, 64, 119, 70, 147, 46, 11, 248, 88, 178, 228, 18, 124, 58, 142, 167, 214, 4, 103, 176, 87, 232, 244, 234, 33, 78, 232, 209, 39, 199, 44, 69, 84, 145, 40, 226, 28, 119, 139, 35, 188, 72, 230, 29, 42, 167, 241, 165, 102, 27, 145, 110, 243, 45, 107, 149, 228, 29, 221, 105, 157, 4, 250, 77, 65, 125, 32, 133, 185, 231, 48, 143, 156, 2, 210, 252, 216, 48, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 61, 48, 33, 48, 9, 6, 5, 43, 14, 3, 2, 26, 5, 0, 4, 20, 180, 216, 120, 155, 0, 112, 93, 199, 9, 124, 85, 225, 145, 167, 242, 210, 67, 232, 47, 64, 4, 20, 118, 64, 12, 165, 214, 213, 187, 145, 17, 163, 12, 112, 66, 189, 245, 214, 240, 52, 36, 141, 2, 2, 4, 0, 0, 0 };
var cert = new X509Certificate2(certraw, "symetria");
In linux-only, I get System.Security.Cryptography.CryptographicException: 'The certificate data cannot be read with the provided password, the password may be incorrect.'
My docker-file is default from Right-click -> Add docker support in visual studio. The docker image is runtime/sdk :5.0-buster
Activity
danmoseley commentedon Mar 19, 2020
@bartonjs regression apparently?
[-]CryptographicException decoding TLS cert in 5.0.0 preview, linux only (Fine in 3.2)[/-][+]CryptographicException decoding TLS cert in 5.0.0 preview, linux only (Fine in 3.1.2)[/+]vcsjones commentedon Mar 19, 2020
I'll have a look.
vcsjones commentedon Mar 19, 2020
Full stack for reference.
Unhandled exception. System.Security.Cryptography.CryptographicException: The certificate data cannot be read with the provided password, the password may be incorrect.
vcsjones commentedon Mar 19, 2020
Reduced test case, this fails in Linux but works on Windows.
joshlangs commentedon Mar 19, 2020
@vcsjones ... I feel the need to inform you that you are a genius. Just sayin'.
vcsjones commentedon Mar 19, 2020
@JoshLang @bartonjs gist of the issue is that the
ECPrivateKeyis missing the public key. As defined in https://www.secg.org/sec1-v2.pdf part C.4, the public key is optional.Basically, we're running in to this condition:
runtime/src/libraries/Common/src/System/Security/Cryptography/EccKeyFormatHelper.cs
Lines 108 to 109 in f80a514
The private key does carry the private key, so it seems that Windows is re-deriving the public key from the private key. The PKCS8 helpers require the pre-calculated public key. The comment there makes me think this is a known limitation. The behavior difference is that on Windows, CNG handles all of the PKCS8 key import. On Linux, it is decoded and the parameters are imported manually.
It regressed in .NET Core 5.0 because the PKCS12 reader is going from a "implemented mostly with OpenSSL" to a more managed implementation. The no-public-key limitation exists in 3.1, however PKCS12 reading didn't use it until 5.0. I would assume that OpenSSL's PKCS12 reader is also re-deriving the public key when needed.
As a work around, if you round-trip your certifcate / p12 through openssl, the re-exported contents will work in .NET Core 5.0.
Where
key.p12is a file containing the bytes ofcertraw, and and thenre-exported.12contains the bytes with it fixed up.bartonjs commentedon Mar 19, 2020
So I guess we need to look into whether we can get an import to work when we have D but not Q.
My gut says that something (probably macOS) was too picky about something with PKCS#8, which is why I didn't send it to the native layers on Unix systems. (Windows CNG respects some attributes to limit key usage, and we ignore attributes, so we had to ask Windows to do the import for us on Windows)
vcsjones commentedon Mar 19, 2020
@bartonjs
I don't know about macOS, but for openssl we can re-calculate it with
EC_KEY_set_private_keyEC_POINT_mul, and finallyEC_POINT_point2bnsince we have the curve. I don't know where to begin to look at this for macOS.Is it worth fixing for the openssl code path at least?
joshlangs commentedon Mar 19, 2020
I've run into this D but not Q limitation several times before, whether for this, or stuff like deriving bitcoin addresses from private keys, etc.
I must admit... I've always wondered - why not just do the calculation? I'm only familiar with a couple curves - so maybe it's not so easy as an EC multiplication for all cases?
bartonjs commentedon Mar 19, 2020
We don't have an ECC calculator in the .NET layer; we work with the underlying system libraries opaquely through key objects... so then we're subject to limitations they have at the import/export/create boundary.
Absent the PFX regression I'd say it's a nice-to-have enhancement. Given the context of this report, I'd say we should do it, to prevent the regression.
Looks like it might be
with proper error checking, of course. We could do that in https://github.com/dotnet/runtime/blob/master/src/libraries/Native/Unix/System.Security.Cryptography.Native/pal_ecc_import_export.c#L374 as an
else if (d != NULL).If we can make Q.X == null && Q.Y == null work for Windows (worst case? make a PKCS#8 😄) and macOS, we can just soften the constraints in ImportParameters to require
((Y == null) == (X == null)) && (X != null || D != null). I'd rather not soften them in only one OS family.1 remaining item
joshlangs commentedon Mar 19, 2020
Fixing it has my vote too (even though there's a workaround).
We generate certificates using the popular Certes library to generate TLS certificates from Let's Encrypt. I imagine that it's a common enough scenario that it's worth fixing.
^-- easy fix. Just import BouncyCastle into .net core runtime. ............lol
joshlangs commentedon Mar 19, 2020
Unfortunately, this doesn't work (or I'm doing it wrong).
The command used to transform:
openssl pkcs12 -in cert.pfx -out out.pfx -passin pass:symetria -passout pass:symetriaTest code - the raw byte array is the
out.pfxoutputted above:In windows, the certificate will not load. I get an
WindowsCryptographicExceptionwith messageCannot find the requested object.In linux, the certificate loads successfully. However, later:
vcsjones commentedon Mar 20, 2020
Oh, I thought I saw this work, I'm guessing I did something silly. (See, there is plenty of time left for me to prove I am not a genius) It's actually outputting a textual dump of the p12 file.
Let me see again..
vcsjones commentedon Mar 20, 2020
Looking closer at this, OpenSSL seems to be trying really really hard to preserve the key as-written. The easiest thing at this point I think would be to do
File.WriteAllBytes("out.p12", cert.Export(X509ContentType.Pkcs12, "password"))from Windows and let Windows write the P12 from scratch.joshlangs commentedon Mar 20, 2020
Our pipeline, including certificate generation, all runs in linux. I'll see if I can find a different workaround. I'll post if I find one.
joshlangs commentedon Mar 20, 2020
I understand it's complex. I really think it should be considered one day, lest ye always be chasing inconsistencies between platforms.
vcsjones commentedon Mar 20, 2020
I did some noodling to fix this in #33874. The Linux/OpenSSL case works, macOS I am tinkering with. I think this is doable in macOS, but I have the world's slowest Mac which doesn't help that macOS's APIs around all of this makes little sense to me.
@bartonjs instead of broadly permitting ECParameters Q to allow a null point, how would you feel about making a more targeting fix just for the Pkcs8/ECPrivateKey import code paths to start? I'm not suggesting it one way or the other right now, but it might be easier and wondering if that's sensible.
bartonjs commentedon Mar 20, 2020
ImportParameters is abstract, so all custom types have to implement it. Doing magic in the PKCS8/ECPrivateKey layer means all custom types have to do the same "OK, I'll let this work" magic.
Sure, some types might end up needing to reject no-Q; but that seems easier for them to handle than intercepting the other import flows.
So... I'd rather not; but if it's complicatedly required, then I'll accept it.
danmoseley commentedon Mar 24, 2020
@bartonjs is this widespread enough impact that we should try to hurry it into preview 3? I see only one report above.
vcsjones commentedon Mar 27, 2020
@bartonjs another thought if we want something soonish for Preview 3: I have it working in CNG and OpenSSL, still need to figure out MacOS (haven't ruled it out..). Would you take a PR that fixes CNG/OpenSSL and MacOS throws a PNSE, and a separate PR to get MacOS working, or prefer to try and get it in all in one go?
Trying to figure if I should focus on MacOS or getting what I have polished and fully tested.
bartonjs commentedon Mar 27, 2020
@vcsjones Let's go with "polish and PR". Maybe one of us, or a mysterious third party, will come up with something easy to slide in for macOS before it gets merged.
vcsjones commentedon Apr 9, 2020
@JoshLang
This has been fixed. I don't believe the fixes made the cut for preview3, but I did confirm that your original repro works with the latest nightly on Linux.
This limitation has been removed. An EC private key that does not contain Q but does contain D will now work, and Q will be re-derived by the platform as needed.
joshlangs commentedon Apr 9, 2020
@vcsjones Thanks! I saw the pull request close yesterday, with much excitement :D I kept refreshing nuget to see if preview3 was out.
Alas, I'll be patient and wait for the next one!
Thanks for taking care of this.